tarantool / vshard

The new generation of sharding based on virtual buckets
Other
100 stars 30 forks source link

storage: introduce `on_bucket_event` trigger #373

Closed Serpentian closed 1 year ago

Serpentian commented 1 year ago

Buckets migration looks like a regular client data activity, indistinguishable in the replication flow. In order to allow efficient change data capturing we can add a fake operation in the beginning of the transaction, so that a client could determing which operations can be skipped (using HEADER.tsn) as they were done not by the user but by gc or rebalancer.

In order not to implement "dirty hack" with special cases, this commit introduces the ability for a user to set the trigger.

Closes https://github.com/tarantool/vshard/issues/372

Co-authored-by: Vladislav Shpilevoy v.shpilevoy@tarantool.org

@TarantoolBot document Title: vshard.storage.on_bucket_event()

vshard.storage.on_bucket_event([trigger-function[, old-trigger-function]])

Create a trigger, which is executed when the data from the user spaces is changed (deleted or inserted) due to the rebalancing process. It's triggered on every data batch changed.

Parameters:

Return: nil or function pointer

As everything executed inside triggers is already in a transaction, you shouldn't use transactions, yield-operations, changes to different space engines.

The trigger-function can have up to three parameters:

Example

vshard.storage.on_bucket_event(function(event, bucket_id, data)
    if event == 'bucket_data_recv_txn' then
        -- Handle it.
        for idx, space in ipairs(data.spaces) do
            ...
        end
    elseif event == 'bucket_data_gc_txn' then
        -- Handle it.
        ...
    end
end)
Serpentian commented 1 year ago

There is a new proposal in the ticket: #372 (comment). This way might be much less crutchy and significantly more useful in general. Can you talk to customers of this feature if they can leverage the triggers-way like described in the comment instead of us doing those spaces in master?

Agree with you, this solution is a big crutch, triggers looks much better. Don't really think they will be against this idea, but I'll definitely ask them.