Details
-
Sub-task
-
Status: Closed
-
Major
-
Resolution: Fixed
-
None
-
None
Description
- SCM allocates ids in a batch way. It maintains three fields: firstId, lastId and nextId. It saves the lastId in rocksDB, saves firstId and lastId in memory. The initial value of nextId is firstId.
- When getNextId() is called, if nextId is less than lastId, SCM just returns nextId and increases it, otherwise it calls allocateBatch(expectedLastId, newLastId) to allocate a batch of ids, then serves the request.
- In allocateBatch(expectedLastId, newLastId) , it works in CAS way:
- it reads lastId from rocksDB.
- if lastId equals expectedLastId, it saves newLastId into rocksDB, returns success, otherwise it rejects the allocation request.
- It also provides a getLastId() to read lastId from rocksDB. The allocation works in a loop way: