Does fluid-framework support transactions?

Viewed 241

For example, in FluidFramework/examples/data-objects/badge/src/BadgeClient.tsx:

    const changeSelectedOption = (newItem: IBadgeType): void => {
        if (newItem.key !== model.currentCell.get().key) {
            const len = model.historySequence.getItemCount();
            model.historySequence.insert(len, [
                {
                    value: newItem,
                    timestamp: new Date(),
                },
            ]);
            model.currentCell.set(newItem);
        }
    };

Does the history-insertion op always succeed/fail together with the cell-setting op?

2 Answers

Fluid does not support transactions in the traditional sense, but Fluid does have "Group Ops." These can be created using the orderSequentially api on the ContainerRuntime. Some DDS have a wrapper around this container level API.

Group Ops allow you to pack a group of operations into one message, so that the Fluid ordering service adds those ops to the Total Order Broadcast in order.

Ops can only be grouped within one container because that is the boundary of the total order broadcast. Ops can be grouped across DDS within one container. This is still different than a transaction because we don't guarantee roll back of the earlier ops in the event that a later op is invalid.

You can see an example in the Sequence DDS.

Below, we'll submit two ops for "hello" and "world" in one group op, ensuring that helloworld will be submitted all at once with no interleaving input.

const op1 = {
    pos: 0,
    seg: "hello",
    type: MergeTreeDeltaType.INSERT,
}

const op2 = {
    pos: 5,
    seg: "world"
    type: MergeTreeDeltaType.INSERT,
}

const groupOp = {
    ops: [op1, op2],
    type: MergeTreeDeltaType.GROUP,
}

sharedString.groupOperation(groupOp);

The ProseMirror fluid object has more in depth code

Not transactions but it does support batches. Batches guarantee no other operations will be interleaved between the ops in the batch. You can create a batch by using the orderSequentially Api

Related