IncrementAndGet Atomic Operation

Is it possible to have an MutationType which will increment an number and also return the new value ? Any layer implementation which relies on a primary key feature will need this feature.

Current op that just Adds a value is not usable as a primary key generator as there is no reliable way to get the value which was just incremented. I understand that this operation will not be in scope of the existing transaction boundary as the incremented value cant be rolled back. But I think this is an acceptable scenario.

I read the High-Contention-Allocator algorithm but I dont think it fits the usecase.

With respect to an IncrementAndGet op, it’s not possible to get the value immediately with a no-read atomic increment because the value will not be known until some (asynchronous) point after the commit. There has been a prior request to be able to access this value eventually when it is known, and you can see https://github.com/apple/foundationdb/issues/627 for that discussion.

As to implementing a primary key, versionstamps are likely to be helpful here. There’s some discussion on the above linked thread and various other forum posts about these as well, but the basic idea is that you can insert into your keys and values a versionstamp that will be replaced at commit time by a monotonically increasing unique value. You can use the same stamp in multiple places in the same transaction, and you can also inspect the value after the transaction commits.

1 Like