class IdPool

This class implements a surrogate identifier pool for the DB tables SI.Terms, SI.Users, and SI.Users.

class seaice.IdPool.IdPool(db_con, table)[source]

A thread-safe object for producing and consuming table row IDs within a particluar context, i.e. SI.Terms, SI.Users, and SI.Comments. When initialized, an instance queries the table for all assigned IDs in ascending order. Continuous regions of unassigned IDs are found and added to the pool. The highest assigned ID is noticed so that when the pool is empty, the producer function returns the next highest avaialble.

TODO This could be made more space-efficient by combining contiguous free IDs into ranges.

Parameters:
  • db_con (seaice.SeaIceConnector.SeaIceConnector) – Connection to the SeaIce database.
  • table (str) – Name of the table for which a pool will be created. The table should have a column of surrogate ID scalled “id”.
ConsumeId()[source]

Consume the next available ID.

Return type:int
GetNextId()[source]

Get the next ID without consuming it (look ahead).

Return type:int
ReleaseId(id)[source]

Release and ID back into the pool (produce)

Parameters:id (int) – Surrogate ID.

Previous topic

class ConnectorPool

Next topic

the user module

This Page