Badger Transactions of two Buckets

Hi,

I know Badger does not support buckets like BoltDB, but I’m trying to simulate two buckets in Badger.

Method 1:

Open two Badger DBs to simulate two buckets, however, transactions of two DBs (update both or neither) becomes a problem.

Method 2:

Open only one Badger DB, use key prefixes (like first byte set to 1 or 2) to differentiate the two buckets. Transactions should work well but I’m not sure if this model is sufficient to simulate two buckets.

Do you have a workaround for transactions of two Badger DBs? Which method would you recommend?

Hal

Using key prefixes should work. That’s what we do when encoding different ‘buckets’ in Dgraph. The only trick to be careful of is to make all of the key prefixes a fixed size (e.g. 1 byte, or 2 bytes etc), so that it’s easy to tell which part of the key is the bucket identifier and which part of the key is the remainder.

1 Like

I agree. Fixed length prefixes are a good substitute for simulating buckets; and a very natural one.

1 Like

This topic was automatically closed 30 days after the last reply. New replies are no longer allowed.