8
0
mirror of https://github.com/FirebirdSQL/firebird.git synced 2025-01-22 20:03:02 +01:00

CORE-6300 (next attachment/statement ID) and some other additions

This commit is contained in:
Dmitry Yemanov 2020-08-09 12:28:43 +03:00
parent a2d8bc8c6c
commit 22ad236f62
13 changed files with 138 additions and 31 deletions

View File

@ -83,6 +83,10 @@ Monitoring tables
- MON$CRYPT_PAGE (number of page being encrypted / decrypted)
- MON$OWNER (database owner name)
- MON$SEC_DATABASE (security database)
- MON$GUID (database GUID)
- MON$FILE_ID (unique filesystem-level ID)
- MON$NEXT_ATTACHMENT (next attachment number)
- MON$NEXT_STATEMENT (next statement number)
MON$ATTACHMENTS (connected attachments)
- MON$ATTACHMENT_ID (attachment ID)

View File

@ -84,6 +84,10 @@ Usage:
| name if connectivity via file names is not allowed or
| fully expanded database file name otherwise.
|
DB_GUID | GUID of the current database
|
DB_FILE_ID | Unique filesystem-level ID of the current database
|
ISOLATION_LEVEL | Isolation level for current transaction. Returned values
| are "READ COMMITTED", "CONSISTENCY", "SNAPSHOT"
|

View File

@ -165,6 +165,12 @@ enum db_info_types
// Return list of features supported by provider of current connection
fb_info_features = 141,
fb_info_next_attachment = 142,
fb_info_next_statement = 143,
fb_info_db_guid = 144,
fb_info_db_file_id = 145,
isc_info_db_last_value /* Leave this LAST! */
};

View File

@ -88,6 +88,20 @@ namespace Jrd
return dbb_tip_cache->generateStatementId();
}
AttNumber Database::getLatestAttachmentId() const
{
if (!dbb_tip_cache)
return 0;
return dbb_tip_cache->getLatestAttachmentId();
}
StmtNumber Database::getLatestStatementId() const
{
if (!dbb_tip_cache)
return 0;
return dbb_tip_cache->getLatestStatementId();
}
const Firebird::string& Database::getUniqueFileId()
{
if (dbb_file_id.isEmpty())

View File

@ -613,6 +613,8 @@ public:
StmtNumber generateStatementId();
// void assignLatestTransactionId(TraNumber number);
void assignLatestAttachmentId(AttNumber number);
AttNumber getLatestAttachmentId() const;
StmtNumber getLatestStatementId() const;
USHORT getMaxIndexKeyLength() const
{

View File

@ -817,14 +817,14 @@ SINT64 Monitoring::getGlobalId(int value)
void Monitoring::putDatabase(thread_db* tdbb, SnapshotData::DumpRecord& record)
{
const Database* const database = tdbb->getDatabase();
const auto dbb = tdbb->getDatabase();
record.reset(rel_mon_database);
// Determine the backup state
int backup_state = backup_state_unknown;
BackupManager* const bm = database->dbb_backup_manager;
BackupManager* const bm = dbb->dbb_backup_manager;
if (bm && !bm->isShutDown())
{
@ -844,78 +844,78 @@ void Monitoring::putDatabase(thread_db* tdbb, SnapshotData::DumpRecord& record)
}
}
PathName databaseName(database->dbb_database_name);
PathName databaseName(dbb->dbb_database_name);
ISC_systemToUtf8(databaseName);
// database name or alias (MUST BE ALWAYS THE FIRST ITEM PASSED!)
record.storeString(f_mon_db_name, databaseName);
// page size
record.storeInteger(f_mon_db_page_size, database->dbb_page_size);
record.storeInteger(f_mon_db_page_size, dbb->dbb_page_size);
// major ODS version
record.storeInteger(f_mon_db_ods_major, database->dbb_ods_version);
record.storeInteger(f_mon_db_ods_major, dbb->dbb_ods_version);
// minor ODS version
record.storeInteger(f_mon_db_ods_minor, database->dbb_minor_version);
record.storeInteger(f_mon_db_ods_minor, dbb->dbb_minor_version);
// oldest interesting transaction
record.storeInteger(f_mon_db_oit, database->dbb_oldest_transaction);
record.storeInteger(f_mon_db_oit, dbb->dbb_oldest_transaction);
// oldest active transaction
record.storeInteger(f_mon_db_oat, database->dbb_oldest_active);
record.storeInteger(f_mon_db_oat, dbb->dbb_oldest_active);
// oldest snapshot transaction
record.storeInteger(f_mon_db_ost, database->dbb_oldest_snapshot);
record.storeInteger(f_mon_db_ost, dbb->dbb_oldest_snapshot);
// next transaction
record.storeInteger(f_mon_db_nt, database->dbb_next_transaction);
record.storeInteger(f_mon_db_nt, dbb->dbb_next_transaction);
// number of page buffers
record.storeInteger(f_mon_db_page_bufs, database->dbb_bcb->bcb_count);
record.storeInteger(f_mon_db_page_bufs, dbb->dbb_bcb->bcb_count);
int temp;
// SQL dialect
temp = (database->dbb_flags & DBB_DB_SQL_dialect_3) ? 3 : 1;
temp = (dbb->dbb_flags & DBB_DB_SQL_dialect_3) ? 3 : 1;
record.storeInteger(f_mon_db_dialect, temp);
// shutdown mode
if (database->dbb_ast_flags & DBB_shutdown_full)
if (dbb->dbb_ast_flags & DBB_shutdown_full)
temp = shut_mode_full;
else if (database->dbb_ast_flags & DBB_shutdown_single)
else if (dbb->dbb_ast_flags & DBB_shutdown_single)
temp = shut_mode_single;
else if (database->dbb_ast_flags & DBB_shutdown)
else if (dbb->dbb_ast_flags & DBB_shutdown)
temp = shut_mode_multi;
else
temp = shut_mode_online;
record.storeInteger(f_mon_db_shut_mode, temp);
// sweep interval
record.storeInteger(f_mon_db_sweep_int, database->dbb_sweep_interval);
record.storeInteger(f_mon_db_sweep_int, dbb->dbb_sweep_interval);
// read only flag
temp = database->readOnly() ? 1 : 0;
temp = dbb->readOnly() ? 1 : 0;
record.storeInteger(f_mon_db_read_only, temp);
// forced writes flag
temp = (database->dbb_flags & DBB_force_write) ? 1 : 0;
temp = (dbb->dbb_flags & DBB_force_write) ? 1 : 0;
record.storeInteger(f_mon_db_forced_writes, temp);
// reserve space flag
temp = (database->dbb_flags & DBB_no_reserve) ? 0 : 1;
temp = (dbb->dbb_flags & DBB_no_reserve) ? 0 : 1;
record.storeInteger(f_mon_db_res_space, temp);
// creation date
record.storeTimestampTz(f_mon_db_created, database->dbb_creation_date);
record.storeTimestampTz(f_mon_db_created, dbb->dbb_creation_date);
// database size
record.storeInteger(f_mon_db_pages, PageSpace::actAlloc(database));
record.storeInteger(f_mon_db_pages, PageSpace::actAlloc(dbb));
// database backup state
record.storeInteger(f_mon_db_backup_state, backup_state);
// crypt thread status
if (database->dbb_crypto_manager)
if (dbb->dbb_crypto_manager)
{
record.storeInteger(f_mon_db_crypt_page, database->dbb_crypto_manager->getCurrentPage());
record.storeInteger(f_mon_db_crypt_state, database->dbb_crypto_manager->getCurrentState());
record.storeInteger(f_mon_db_crypt_page, dbb->dbb_crypto_manager->getCurrentPage());
record.storeInteger(f_mon_db_crypt_state, dbb->dbb_crypto_manager->getCurrentState());
}
// database owner
record.storeString(f_mon_db_owner, database->dbb_owner);
record.storeString(f_mon_db_owner, dbb->dbb_owner);
// security database type
PathName secDbName;
string secDbType = "Other";
expandDatabaseName(database->dbb_config->getSecurityDatabase(), secDbName, NULL);
if (secDbName == database->dbb_filename)
expandDatabaseName(dbb->dbb_config->getSecurityDatabase(), secDbName, NULL);
if (secDbName == dbb->dbb_filename)
secDbType = "Self";
else
{
@ -925,17 +925,26 @@ void Monitoring::putDatabase(thread_db* tdbb, SnapshotData::DumpRecord& record)
secDbType = "Default";
}
record.storeString(f_mon_db_secdb, secDbType);
record.storeInteger(f_mon_db_na, dbb->getLatestAttachmentId());
record.storeInteger(f_mon_db_ns, dbb->getLatestStatementId());
char guidBuffer[GUID_BUFF_SIZE];
GuidToString(guidBuffer, &dbb->dbb_guid);
record.storeString(f_mon_db_guid, string(guidBuffer));
record.storeString(f_mon_db_file_id, dbb->getUniqueFileId());
// statistics
const int stat_id = fb_utils::genUniqueId();
record.storeGlobalId(f_mon_db_stat_id, getGlobalId(stat_id));
record.write();
if (database->dbb_flags & DBB_shared)
if (dbb->dbb_flags & DBB_shared)
{
MutexLockGuard guard(database->dbb_stats_mutex, FB_FUNCTION);
putStatistics(record, database->dbb_stats, stat_id, stat_database);
putMemoryUsage(record, database->dbb_memory_stats, stat_id, stat_database);
MutexLockGuard guard(dbb->dbb_stats_mutex, FB_FUNCTION);
putStatistics(record, dbb->dbb_stats, stat_id, stat_database);
putMemoryUsage(record, dbb->dbb_memory_stats, stat_id, stat_database);
}
else
{

View File

@ -338,6 +338,8 @@ const char
EXT_CONN_POOL_ACTIVE[] = "EXT_CONN_POOL_ACTIVE_COUNT",
EXT_CONN_POOL_LIFETIME[] = "EXT_CONN_POOL_LIFETIME",
REPLICATION_SEQ_NAME[] = "REPLICATION_SEQUENCE",
DATABASE_GUID[] = "DB_GUID",
DATABASE_FILE_ID[] = "DB_FILE_ID",
// SYSTEM namespace: connection wise items
SESSION_ID_NAME[] = "SESSION_ID",
NETWORK_PROTOCOL_NAME[] = "NETWORK_PROTOCOL",
@ -4174,6 +4176,16 @@ dsc* evlGetContext(thread_db* tdbb, const SysFunction*, const NestValueArray& ar
resultStr.printf("%s.%s.%s", FB_MAJOR_VER, FB_MINOR_VER, FB_REV_NO);
else if (nameStr == DATABASE_NAME)
resultStr = dbb->dbb_database_name.ToString();
else if (nameStr == DATABASE_GUID)
{
char guidBuffer[GUID_BUFF_SIZE];
GuidToString(guidBuffer, &dbb->dbb_guid);
resultStr = string(guidBuffer);
}
else if (nameStr == DATABASE_FILE_ID)
{
resultStr = dbb->getUniqueFileId();
}
else if (nameStr == SESSION_ID_NAME)
resultStr.printf("%" SQUADFORMAT, PAG_attachment_id(tdbb));
else if (nameStr == NETWORK_PROTOCOL_NAME)

View File

@ -212,3 +212,4 @@
FIELD(fld_remote_crypt , nam_wire_crypt_plugin, dtype_varying, MAX_SQL_IDENTIFIER_LEN , dsc_text_type_metadata , NULL , true)
FIELD(fld_pub_name , nam_pub_name , dtype_text , MAX_SQL_IDENTIFIER_LEN , dsc_text_type_metadata , NULL , false)
FIELD(fld_file_id , nam_file_id , dtype_varying , 255 , dsc_text_type_ascii , NULL , false)

View File

@ -878,6 +878,31 @@ void INF_database_info(thread_db* tdbb,
break;
}
case fb_info_next_attachment:
length = INF_convert(dbb->getLatestAttachmentId(), buffer);
break;
case fb_info_next_statement:
length = INF_convert(dbb->getLatestStatementId(), buffer);
break;
case fb_info_db_guid:
{
char guidBuffer[GUID_BUFF_SIZE];
GuidToString(guidBuffer, &dbb->dbb_guid);
if (!(info = INF_put_item(item, strlen(guidBuffer), guidBuffer, info, end)))
return;
}
break;
case fb_info_db_file_id:
{
const auto& fileId = dbb->getUniqueFileId();
if (!(info = INF_put_item(item, fileId.length(), fileId.c_str(), info, end)))
return;
}
break;
default:
buffer[0] = item;
item = isc_info_error;

View File

@ -435,3 +435,9 @@ NAME("RDB$PUBLICATIONS", nam_pubs)
NAME("RDB$PUBLICATION_NAME", nam_pub_name)
NAME("RDB$PUBLICATION_TABLES", nam_pub_tables)
NAME("RDB$TABLE_NAME", nam_tab_name)
NAME("RDB$FILE_ID", nam_file_id)
NAME("MON$FILE_ID", nam_mon_file_id)
NAME("MON$GUID", nam_mon_guid)
NAME("MON$NEXT_ATTACHMENT", nam_mon_na)
NAME("MON$NEXT_STATEMENT", nam_mon_ns)

View File

@ -494,6 +494,10 @@ RELATION(nam_mon_database, rel_mon_database, ODS_11_1, rel_virtual)
FIELD(f_mon_db_owner, nam_mon_owner, fld_user, 0, ODS_12_0)
FIELD(f_mon_db_secdb, nam_mon_secdb, fld_sec_db, 0, ODS_12_0)
FIELD(f_mon_db_crypt_state, nam_mon_crypt_state, fld_crypt_state, 0, ODS_13_0)
FIELD(f_mon_db_guid, nam_mon_guid, fld_guid, 0, ODS_13_0)
FIELD(f_mon_db_file_id, nam_mon_file_id, fld_file_id, 0, ODS_13_0)
FIELD(f_mon_db_na, nam_mon_na, fld_att_id, 0, ODS_13_0)
FIELD(f_mon_db_ns, nam_mon_ns, fld_stmt_id, 0, ODS_13_0)
END_RELATION
// Relation 34 (MON$ATTACHMENTS)

View File

@ -1077,6 +1077,24 @@ void TipCache::assignLatestAttachmentId(AttNumber number)
header->latest_attachment_id.store(number, std::memory_order_release);
}
AttNumber TipCache::getLatestAttachmentId() const
{
// Can only be called on initialized TipCache
fb_assert(m_tpcHeader);
GlobalTpcHeader* header = m_tpcHeader->getHeader();
return header->latest_attachment_id;
}
StmtNumber TipCache::getLatestStatementId() const
{
// Can only be called on initialized TipCache
fb_assert(m_tpcHeader);
GlobalTpcHeader* header = m_tpcHeader->getHeader();
return header->latest_statement_id;
}
int TPC_snapshot_state(thread_db* tdbb, TraNumber number)
{
TipCache* cache = tdbb->getDatabase()->dbb_tip_cache;

View File

@ -139,6 +139,8 @@ public:
StmtNumber generateStatementId();
//void assignLatestTransactionId(TraNumber number);
void assignLatestAttachmentId(AttNumber number);
AttNumber getLatestAttachmentId() const;
StmtNumber getLatestStatementId() const;
CommitNumber getGlobalCommitNumber() const
{