Skip to content

PATCH - Object Modification

A method for creating new versions of objects based on existing ones without fully rewriting the data. This results in a new object identifier being generated.

Key features:

  • Creates new objects based on existing ones;
  • Does not require full data transfer;
  • Supports two types of changes:
  • Modification of metadata (attributes);
  • Partial content updates.
  • Keeps the original object unchanged.

Arguments:

  1. Execution context
  2. Method arguments, which includes:
    • Container ID
    • Object ID
    • Attributes (optional)
    • Payload for replace (optional)
    • Additional headers (optional)

Result:

  • new Object ID
 1
 2
 3
 4
 5
 6
 7
 8
 9
10
11
12
13
14
15
16
17
18
19
func PatchObject(ctx context.Context, p pool.Pool) error {
    var (
        prmPatch pool.PrmObjectPatch
        addr     oid.Address
    )

    addr.SetContainer(cnrID)
    addr.SetObject(objID.ObjectID)

    prmPatch.SetNewAttributes(attributes)
    prmPatch.SetAddress(addr)
    prmPatch.SetPayloadReader(bytes.NewReader([]byte("test")))
    prmPatch.SetReplaceAttributes(true)
    var rng object.Range
    rng.SetOffset(0)
    rng.SetLength(7)
    prmPatch.SetRange(&rng)
    prmPatchRes, err := p.PatchObject(ctx, prmPatch)
}
 1
 2
 3
 4
 5
 6
 7
 8
 9
10
11
12
public static void patchObject(FrostFSClient frostFSClient, CallContext callContext, ObjectId oid, ContainerId cid, InputStream patch) {
    var attribute1 = new ObjectAttribute("Filename", "test.jpg");
    var attribute2 = new ObjectAttribute("Attribute", "test");
    var patch = PrmObjectPatch.builder().address(new Address(oid, cid))
            .replaceAttributes(false) // false = add to existing
            .newAttributes(List.of(attribute1, attribute2))
            .payload(patch)
            .range(new Range(0L, 10L)) // Replacement range  (0-10 byte)
            .build();

    var newOid = frostFSClient.patchObject(patch, callContext);
}
 1
 2
 3
 4
 5
 6
 7
 8
 9
10
11
12
13
14
15
16
17
18
19
20
21
 public static async Task<FrostFsObjectId> PatchObjectAsync(
    FrostFSClient client, 
    FrostFsContainerId containerId, 
    FrostFsObjectId objectId,
    byte[] patch, 
    ulong patchOffset,
    FrostFsAttributePair[] attributes,
    bool replaceAttributes)
{
    FrostFsRange range = new (patchOffset, (ulong)patch.Length);

    var patchParams = new PrmObjectPatch(
        address: new FrostFsAddress(containerId, objectId),
        payload: new MemoryStream(patch ?? []),
        maxChunkLength: 3*1024*1024,
        range: range,
        replaceAttributes: replaceAttributes,
        newAttributes: attributes);

    return await client.PatchObjectAsync(patchParams, default);
}