public class UserTableStatUpdater
extends java.lang.Object
_usertablestat
VST.
For performance reasons we do not update the table immediately when the value of one of
its counters is updated. This will be too expensive since the counters are updated very often
but their values are retrieved rarely (if retrieved at all).
We keep the up-to-date values of the counters in memory (see tableStats
map) and flush
them to the underlying table only when the application tries to retrieve the table data.
The flushes are "incremental", so we maintain the the 'version' of the statistics
in-memory record and the version of the most recently persisted state (see TableState
.
An additional optimization is achieved my maintaining the versions of the in-memory and
persisted statistics. This allows us in some situation to completely avoid iteration over
in-memory data and persist
just returns.Modifier and Type | Class and Description |
---|---|
private static interface |
UserTableStatUpdater.Action
Runnable which can throw an Exception.
|
static interface |
UserTableStatUpdater.MinimalUsertablestat
Interface which defines the minimally required methods of the
MinimalUsertablestat interface. |
private class |
UserTableStatUpdater.Worker
Implements incremental update of the _UserTableStat table
|
Modifier and Type | Field and Description |
---|---|
private java.util.concurrent.atomic.AtomicLong |
databaseVersion
Persisted statistics version
|
private static java.util.Map<Database,UserTableStatUpdater> |
instances
Instances of this class, by primary database
|
private static boolean |
isUserTableStats
Is user table stat metadata in use?
|
private static java.util.logging.Logger |
log
Logger
|
private static int |
MAX_BATCH
Max batch size for commit
|
private Database |
metaDatabase
meta database
|
private java.util.concurrent.atomic.AtomicLong |
nextPrimaryKey
Next available primary key for a new _UserTableStat metadata record
|
private Persistence |
persistence
meta database Persistence
|
private SecurityManager |
securityManager
Security manager
|
private java.util.concurrent.atomic.AtomicLong |
statisticsVersion
In-memory statistics version
|
private java.util.concurrent.ConcurrentMap<integer,java.util.concurrent.ConcurrentMap<integer,TableStats>> |
tableStats
Tables' CRUD operations statistics per connection
|
private UserTableStatUpdater.MinimalUsertablestat |
usertablestat
MetaUsertablestatImpl DMO proxy
|
private static java.lang.String |
USERTABLESTAT_TABLE
Usertablestat meta-table name
|
private MetaTableWrapper<UserTableStatUpdater.MinimalUsertablestat> |
usertablestatWrapper
MetaUsertablestat DMO wrapper
|
Constructor and Description |
---|
UserTableStatUpdater(Database metaDatabase)
Constructor.
|
Modifier and Type | Method and Description |
---|---|
static void |
create(Database db,
RecordBuffer buffer)
Register create operation.
|
static void |
delete(Database db,
RecordBuffer buffer)
Register delete operation.
|
void |
disconnected(Session session,
int64 connectId)
Drop data for the closed connection.
|
void |
disconnected(Session session,
java.lang.Integer connectId)
Drop data for the closed connection.
|
static UserTableStatUpdater |
get(Database database)
Get the instance of this class associated with the given metadata database, creating and mapping it
to the database first, if necessary.
|
SecurityManager |
getSecurityManager()
Get the SecurityManager instance.
|
TableStats |
getTableStats(integer connectId,
integer tableNo)
Get table statistics holder for a give connection and table
|
boolean |
persist()
Persist statistics in the meta database
|
static void |
persist(Database database)
Persist statistics in the meta database
|
static void |
retrieve(Database db,
RecordBuffer buffer)
Register retrieve operation.
|
private static java.util.Optional<TableStats> |
stat(Database db,
RecordBuffer buffer)
Retrieve the table statistics record.
|
private static void |
uninterruptibly(UserTableStatUpdater.Action action)
Execute action uninterruptibly.
|
static void |
update(Database db,
RecordBuffer buffer)
Register update operation
|
private static final java.util.logging.Logger log
private static final int MAX_BATCH
private static final java.lang.String USERTABLESTAT_TABLE
private static final boolean isUserTableStats
private static final java.util.Map<Database,UserTableStatUpdater> instances
private final MetaTableWrapper<UserTableStatUpdater.MinimalUsertablestat> usertablestatWrapper
private final UserTableStatUpdater.MinimalUsertablestat usertablestat
private final Database metaDatabase
private final Persistence persistence
private final SecurityManager securityManager
private final java.util.concurrent.ConcurrentMap<integer,java.util.concurrent.ConcurrentMap<integer,TableStats>> tableStats
private final java.util.concurrent.atomic.AtomicLong databaseVersion
private final java.util.concurrent.atomic.AtomicLong statisticsVersion
private final java.util.concurrent.atomic.AtomicLong nextPrimaryKey
public UserTableStatUpdater(Database metaDatabase)
metaDatabase
- meta databasepublic static UserTableStatUpdater get(Database database)
database
- Primary database whose stats are tracked by the associated instance.public static void persist(Database database)
database
- Primary database.public static void create(Database db, RecordBuffer buffer)
db
- Primary database.buffer
- target bufferpublic static void retrieve(Database db, RecordBuffer buffer)
db
- Primary database.buffer
- target bufferpublic static void update(Database db, RecordBuffer buffer)
db
- Primary database.buffer
- target bufferpublic static void delete(Database db, RecordBuffer buffer)
db
- Primary database.buffer
- target bufferprivate static java.util.Optional<TableStats> stat(Database db, RecordBuffer buffer)
db
- Primary databasebuffer
- target bufferprivate static void uninterruptibly(UserTableStatUpdater.Action action) throws java.lang.Exception
action
- action to be executedjava.lang.Exception
public SecurityManager getSecurityManager()
public TableStats getTableStats(integer connectId, integer tableNo)
connectId
- connection idtableNo
- table numberpublic boolean persist() throws PersistenceException
true
if success.PersistenceException
public void disconnected(Session session, java.lang.Integer connectId)
connectId
- Connection ID.public void disconnected(Session session, int64 connectId) throws PersistenceException
session
- Database session.connectId
- Connection ID.PersistenceException
- if an error occurs executing the database update.