|
|||||||||
PREV CLASS NEXT CLASS | FRAMES NO FRAMES | ||||||||
SUMMARY: NESTED | FIELD | CONSTR | METHOD | DETAIL: FIELD | CONSTR | METHOD |
java.lang.Objectcom.sleepycat.je.dbi.DbTree
public class DbTree
DbTree represents the database directory for this environment. DbTree is itself implemented through two databases. The nameDatabase maps databaseName-> an internal databaseId. The idDatabase maps databaseId->DatabaseImpl. For example, suppose we have two databases, foo and bar. We have the following structure: nameDatabase idDatabase IN IN | | BIN BIN +-------------+--------+ +---------------+--------+ . | | . | | NameLNs NameLN NameLN MapLNs for MapLN MapLN for internal key=bar key=foo internal dbs key=53 key=79 dbs data= data= data= data= dbId79 dbId53 DatabaseImpl DatabaseImpl | | Tree for foo Tree for bar | | root IN root IN Databases, Cursors, the cleaner, compressor, and other entities have references to DatabaseImpls. It's important that object identity is properly maintained, and that all constituents reference the same DatabaseImpl for the same db, lest they develop disparate views of the in-memory database; corruption would ensue. To ensure that, all entities must obtain their DatabaseImpl by going through the idDatabase. DDL type operations such as create, rename, remove and truncate get their transactional semantics by transactionally locking the NameLN appropriately. A read-lock on the NameLN, called a handle lock, is maintained for all DBs opened via the public API (openDatabase). This prevents them from being renamed or removed while open. However, for internal database operations, no handle lock on the NameLN is acquired and MapLNs are locked with short-lived non-transactional Lockers. An entity that is trying to get a reference to the DatabaseImpl gets a short lived read lock just for the fetch of the MapLN. A write lock on the MapLN is taken when the database is created, deleted, or when the MapLN is evicted. (see DatabaseImpl.isInUse()) The nameDatabase operates pretty much as a regular application database in terms of eviction and recovery. The idDatabase requires special treatment for both eviction and recovery. The issues around eviction of the idDatabase center on the need to ensure that there are no other current references to the DatabaseImpl other than that held by the mapLN. The presence of a current reference would both make the DatabaseImpl not GC'able, and more importantly, would lead to object identify confusion later on. For example, if the MapLN is evicted while there is a current reference to its DatabaseImpl, and then refetched, there will be two in-memory versions of the DatabaseImpl. Since locks on the idDatabase are short lived, DatabaseImpl.useCount acts as a reference count of active current references. DatabaseImpl.useCount must be modified and read in conjunction with appropriate locking on the MapLN. See DatabaseImpl.isInUse() for details. This reference count checking is only needed when the entire MapLN is evicted. It's possible to evict only the root IN of the database in question, since that doesn't interfere with the DatabaseImpl object identity.
Field Summary | |
---|---|
static DatabaseId |
ID_DB_ID
|
static DatabaseId |
NAME_DB_ID
|
static int |
NEG_DB_ID_START
|
static String |
REP_GROUP_DB_NAME
|
static String |
UTILIZATION_DB_NAME
|
static String |
VLSN_MAP_DB_NAME
|
Constructor Summary | |
---|---|
DbTree()
Create a dbTree from the log. |
|
DbTree(EnvironmentImpl env,
boolean replicationIntended)
Create a new dbTree for a new environment. |
Method Summary | |
---|---|
void |
close()
Release resources and update memory budget. |
DatabaseImpl |
createDb(Locker locker,
String databaseName,
DatabaseConfig dbConfig,
Database databaseHandle)
Creates a new database object given a database name. |
DatabaseImpl |
createInternalDb(Locker locker,
String databaseName,
DatabaseConfig dbConfig)
Create a database for internal use. |
DatabaseImpl |
createReplicaDb(Locker locker,
String databaseName,
DatabaseConfig dbConfig,
NameLN replicatedLN,
ReplicationContext repContext)
Create a replicated database on this client node. |
void |
dbRemove(Locker locker,
String databaseName,
DatabaseId checkId)
Stand alone and Master invocations. |
void |
dbRename(Locker locker,
String databaseName,
String newName)
Stand alone and Master invocations. |
(package private) void |
deleteMapLN(DatabaseId id)
|
long |
doTruncateDb(Locker locker,
String databaseName,
boolean returnCount,
NameLN replicatedLN,
DbOpReplicationContext repContext)
To truncate, remove the database named by databaseName and create a new database in its place. |
void |
dump()
For debugging. |
void |
dumpLog(StringBuilder sb,
boolean verbose)
Write the object into the string buffer for log dumping. |
(package private) String |
dumpString(int nSpaces)
|
DatabaseImpl |
getDb(DatabaseId dbId)
Get a database object based on an id only. |
DatabaseImpl |
getDb(DatabaseId dbId,
long lockTimeout)
Get a database object based on an id only. |
DatabaseImpl |
getDb(DatabaseId dbId,
long lockTimeout,
Map<DatabaseId,DatabaseImpl> dbCache)
Get a database object based on an id only, caching the id-db mapping in the given map. |
DatabaseImpl |
getDb(DatabaseId dbId,
long lockTimeout,
String dbNameIfAvailable)
Get a database object based on an id only. |
DatabaseImpl |
getDb(Locker nameLocker,
String databaseName,
Database databaseHandle)
Get a database object given a database name. |
String |
getDbName(DatabaseId id)
Return the database name for a given db. |
List<String> |
getDbNames()
|
Map<DatabaseId,String> |
getDbNamesAndIds()
|
int |
getHighestLevel()
|
int |
getHighestLevel(DatabaseImpl dbImpl)
|
DatabaseImpl |
getIdDatabaseImpl()
|
List<String> |
getInternalNoLookupDbNames()
Return a list of the names of internally used databases that don't get looked up through the naming tree. |
List<String> |
getInternalNoRepDbNames()
Return a list of the names of internally used databases for all environment types. |
List<String> |
getInternalRepDbNames()
Return a list of the names of internally used databases for replication only. |
int |
getLastLocalDbId()
The last allocated local and replicated db ids are used for ckpts. |
int |
getLastReplicatedDbId()
|
int |
getLogSize()
|
long |
getTransactionId()
|
(package private) long |
getTreeAdminMemory()
|
(package private) void |
initExistingEnvironment(EnvironmentImpl eImpl)
Initialize the db tree during recovery, after instantiating the tree from the log. |
(package private) boolean |
isConverted()
|
(package private) boolean |
isReplicated()
|
static boolean |
isReservedDbName(String name)
Returns true if the name is a reserved JE database name. |
boolean |
logicalEquals(Loggable other)
|
void |
modifyDbRoot(DatabaseImpl db)
Write the MapLN to disk. |
void |
modifyDbRoot(DatabaseImpl db,
long ifBeforeLsn,
boolean mustExist)
Write a MapLN to the log in order to: - propagate a root change - save per-db utilization information - save database config information. |
void |
optionalModifyDbRoot(DatabaseImpl db)
Check deferred write settings before writing the MapLN. |
void |
readFromLog(ByteBuffer itemBuffer,
int entryVersion)
Initialize this object from the data in itemBuf. |
void |
rebuildINListMapDb()
Rebuild the IN list after recovery. |
void |
releaseDb(DatabaseImpl db)
Decrements the use count of the given DB, allowing it to be evicted if the use count reaches zero. |
void |
releaseDbs(Map<DatabaseId,DatabaseImpl> dbCache)
Calls releaseDb for all DBs in the given map of DatabaseId to DatabaseImpl. |
void |
removeReplicaDb(Locker locker,
String databaseName,
DatabaseId checkId,
DbOpReplicationContext repContext)
Replica invocations. |
void |
renameReplicaDb(Locker locker,
String databaseName,
String newName,
NameLN replicatedLN,
DbOpReplicationContext repContext)
Replica invocations. |
(package private) void |
setIsConverted()
|
(package private) void |
setIsReplicated()
|
void |
setLastDbId(int lastReplicatedDbId,
int lastLocalDbId)
Initialize the db ids, from recovery. |
String |
toString()
|
long |
truncate(Locker locker,
String databaseName,
boolean returnCount)
|
long |
truncateReplicaDb(Locker locker,
String databaseName,
boolean returnCount,
NameLN replicatedLN,
DbOpReplicationContext repContext)
|
void |
updateFromReplay(DatabaseId replayDbId)
|
boolean |
verify(VerifyConfig config,
PrintStream out)
|
void |
writeToLog(ByteBuffer logBuffer)
This log entry type is configured to perform marshaling (getLogSize and writeToLog) under the write log mutex. |
Methods inherited from class java.lang.Object |
---|
clone, equals, finalize, getClass, hashCode, notify, notifyAll, wait, wait, wait |
Field Detail |
---|
public static final DatabaseId ID_DB_ID
public static final DatabaseId NAME_DB_ID
public static final String UTILIZATION_DB_NAME
public static final String REP_GROUP_DB_NAME
public static final String VLSN_MAP_DB_NAME
public static final int NEG_DB_ID_START
Constructor Detail |
---|
public DbTree()
public DbTree(EnvironmentImpl env, boolean replicationIntended) throws DatabaseException
DatabaseException
Method Detail |
---|
public int getLastLocalDbId()
public int getLastReplicatedDbId()
public void setLastDbId(int lastReplicatedDbId, int lastLocalDbId)
public void updateFromReplay(DatabaseId replayDbId)
void initExistingEnvironment(EnvironmentImpl eImpl) throws DatabaseException
DatabaseException
public DatabaseImpl createDb(Locker locker, String databaseName, DatabaseConfig dbConfig, Database databaseHandle) throws DatabaseException
DatabaseException
public DatabaseImpl createInternalDb(Locker locker, String databaseName, DatabaseConfig dbConfig) throws DatabaseException
DatabaseException
public DatabaseImpl createReplicaDb(Locker locker, String databaseName, DatabaseConfig dbConfig, NameLN replicatedLN, ReplicationContext repContext) throws DatabaseException
DatabaseException
public void optionalModifyDbRoot(DatabaseImpl db) throws DatabaseException
db
- the database represented by this MapLN
DatabaseException
public void modifyDbRoot(DatabaseImpl db) throws DatabaseException
db
- the database represented by this MapLN
DatabaseException
public void modifyDbRoot(DatabaseImpl db, long ifBeforeLsn, boolean mustExist) throws DatabaseException
db
- the database whose root is held by this MapLNifBeforeLsn
- if argument is not NULL_LSN, only do the write if
this MapLN's current LSN is before isBeforeLSN.mustExist
- if true, throw DatabaseException if the DB does not
exist; if false, silently do nothing.
DatabaseException
public void dbRename(Locker locker, String databaseName, String newName) throws DatabaseNotFoundException
DatabaseNotFoundException
doRenameDb(com.sleepycat.je.txn.Locker, java.lang.String, java.lang.String, com.sleepycat.je.tree.NameLN, com.sleepycat.je.log.DbOpReplicationContext)
public void renameReplicaDb(Locker locker, String databaseName, String newName, NameLN replicatedLN, DbOpReplicationContext repContext) throws DatabaseNotFoundException
DatabaseNotFoundException
doRenameDb(com.sleepycat.je.txn.Locker, java.lang.String, java.lang.String, com.sleepycat.je.tree.NameLN, com.sleepycat.je.log.DbOpReplicationContext)
public void dbRemove(Locker locker, String databaseName, DatabaseId checkId) throws DatabaseNotFoundException
DatabaseNotFoundException
doRemoveDb(com.sleepycat.je.txn.Locker, java.lang.String, com.sleepycat.je.dbi.DatabaseId, com.sleepycat.je.log.DbOpReplicationContext)
public void removeReplicaDb(Locker locker, String databaseName, DatabaseId checkId, DbOpReplicationContext repContext) throws DatabaseNotFoundException
DatabaseNotFoundException
doRemoveDb(com.sleepycat.je.txn.Locker, java.lang.String, com.sleepycat.je.dbi.DatabaseId, com.sleepycat.je.log.DbOpReplicationContext)
public long doTruncateDb(Locker locker, String databaseName, boolean returnCount, NameLN replicatedLN, DbOpReplicationContext repContext) throws DatabaseNotFoundException
returnCount
- if true, must return the count of records in the
database, which can be an expensive option.
DatabaseNotFoundException
- if the operation fails because the
given DB name is not found.public long truncate(Locker locker, String databaseName, boolean returnCount) throws DatabaseNotFoundException
DatabaseNotFoundException
doTruncateDb(com.sleepycat.je.txn.Locker, java.lang.String, boolean, com.sleepycat.je.tree.NameLN, com.sleepycat.je.log.DbOpReplicationContext)
public long truncateReplicaDb(Locker locker, String databaseName, boolean returnCount, NameLN replicatedLN, DbOpReplicationContext repContext) throws DatabaseNotFoundException
DatabaseNotFoundException
doTruncateDb(com.sleepycat.je.txn.Locker, java.lang.String, boolean, com.sleepycat.je.tree.NameLN, com.sleepycat.je.log.DbOpReplicationContext)
void deleteMapLN(DatabaseId id) throws DatabaseException
DatabaseException
public DatabaseImpl getDb(Locker nameLocker, String databaseName, Database databaseHandle) throws DatabaseException
nameLocker
- is used to access the NameLN. As always, a NullTxn
is used to access the MapLN.databaseName
- target database
DatabaseException
public DatabaseImpl getDb(DatabaseId dbId) throws DatabaseException
DatabaseException
public DatabaseImpl getDb(DatabaseId dbId, long lockTimeout) throws DatabaseException
DatabaseException
public DatabaseImpl getDb(DatabaseId dbId, long lockTimeout, Map<DatabaseId,DatabaseImpl> dbCache) throws DatabaseException
DatabaseException
public DatabaseImpl getDb(DatabaseId dbId, long lockTimeout, String dbNameIfAvailable) throws DatabaseException
DatabaseException
public void releaseDb(DatabaseImpl db)
public void releaseDbs(Map<DatabaseId,DatabaseImpl> dbCache)
public void rebuildINListMapDb() throws DatabaseException
DatabaseException
public boolean verify(VerifyConfig config, PrintStream out) throws DatabaseException
DatabaseException
public String getDbName(DatabaseId id) throws DatabaseException
DatabaseException
public Map<DatabaseId,String> getDbNamesAndIds() throws DatabaseException
DatabaseException
public List<String> getDbNames() throws DatabaseException
DatabaseException
public List<String> getInternalNoLookupDbNames()
public List<String> getInternalNoRepDbNames()
public List<String> getInternalRepDbNames()
public static boolean isReservedDbName(String name)
public int getHighestLevel() throws DatabaseException
DatabaseException
public int getHighestLevel(DatabaseImpl dbImpl) throws DatabaseException
DatabaseException
boolean isReplicated()
void setIsReplicated()
boolean isConverted()
void setIsConverted()
public DatabaseImpl getIdDatabaseImpl()
public void close()
long getTreeAdminMemory()
public int getLogSize()
getLogSize
in interface Loggable
Loggable.getLogSize()
public void writeToLog(ByteBuffer logBuffer)
writeToLog
in interface Loggable
logBuffer
- is the destination bufferLoggable.writeToLog(java.nio.ByteBuffer)
public void readFromLog(ByteBuffer itemBuffer, int entryVersion)
Loggable
readFromLog
in interface Loggable
Loggable.readFromLog(java.nio.ByteBuffer, int)
public void dumpLog(StringBuilder sb, boolean verbose)
Loggable
dumpLog
in interface Loggable
sb
- destination string bufferverbose
- if true, dump the full, verbose versionLoggable.dumpLog(java.lang.StringBuilder, boolean)
public long getTransactionId()
getTransactionId
in interface Loggable
Loggable.getTransactionId()
public boolean logicalEquals(Loggable other)
logicalEquals
in interface Loggable
Always return false, this item should never be compared.
String dumpString(int nSpaces)
public String toString()
toString
in class Object
public void dump()
|
|||||||||
PREV CLASS NEXT CLASS | FRAMES NO FRAMES | ||||||||
SUMMARY: NESTED | FIELD | CONSTR | METHOD | DETAIL: FIELD | CONSTR | METHOD |