Skip to content

Commit

Permalink
CORE-4965: Extend the transaction ID space beyond 2^32 transactions. …
Browse files Browse the repository at this point in the history
…Initially developed in the v2.5 custom branch, then reworked and now merged into v3.0.
  • Loading branch information
dyemanov authored and hvlad committed Mar 23, 2016
1 parent 7464e92 commit 1ae6a9b
Show file tree
Hide file tree
Showing 64 changed files with 1,225 additions and 859 deletions.
2 changes: 1 addition & 1 deletion src/alice/alice.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -308,7 +308,7 @@ int alice(Firebird::UtilSvc* uSvc)
ALICE_error(10); // msg 10: transaction number or "all" required
}
ALICE_upper_case(*argv++, string, sizeof(string));
if (!(tdgbl->ALICE_data.ua_transaction = atoi(string)))
if (!sscanf(string, "%"SQUADFORMAT, &tdgbl->ALICE_data.ua_transaction))
{
if (strcmp(string, "ALL")) {
ALICE_error(10); // msg 10: transaction number or "all" required
Expand Down
10 changes: 5 additions & 5 deletions src/alice/alice.h
Original file line number Diff line number Diff line change
Expand Up @@ -79,7 +79,7 @@ struct user_action
bool ua_read_only;
SLONG ua_shutdown_delay;
SLONG ua_sweep_interval;
SLONG ua_transaction;
TraNumber ua_transaction;
SLONG ua_page_buffers;
USHORT ua_debug;
ULONG ua_val_errors[MAX_VAL_ERRORS];
Expand All @@ -100,19 +100,19 @@ class alice_str : public pool_alloc_rpt<UCHAR, alice_type_str>
UCHAR str_data[2];
};

// Transaction block: used to store info about a multidatabase transaction.
// Transaction block: used to store info about a multi-database transaction.
// Transaction Description Record

struct tdr : public pool_alloc<alice_type_tdr>
{
tdr* tdr_next; // next subtransaction
SLONG tdr_id; // database-specific transaction id
tdr* tdr_next; // next sub-transaction
TraNumber tdr_id; // database-specific transaction id
alice_str* tdr_fullpath; // full (possibly) remote pathname
const TEXT* tdr_filename; // filename within full pathname
alice_str* tdr_host_site; // host for transaction
alice_str* tdr_remote_site; // site for remote transaction
FB_API_HANDLE tdr_handle; // reconnected transaction handle
FB_API_HANDLE tdr_db_handle; // reattached database handle
FB_API_HANDLE tdr_db_handle; // re-attached database handle
USHORT tdr_db_caps; // capabilities of database
USHORT tdr_state; // see flags below
};
Expand Down
7 changes: 4 additions & 3 deletions src/alice/alice_meta.epp
Original file line number Diff line number Diff line change
Expand Up @@ -164,7 +164,7 @@ void MET_get_state(ISC_STATUS* user_status, tdr* trans)
* in other databases.
*/

tdr* MET_get_transaction(ISC_STATUS* user_status, isc_db_handle handle, SLONG id)
tdr* MET_get_transaction(ISC_STATUS* user_status, isc_db_handle handle, TraNumber id)
{
FB_API_HANDLE request = 0;
tdr* trans = NULL;
Expand Down Expand Up @@ -328,7 +328,8 @@ static tdr* get_description(ISC_QUAD* blob_id)
++p;

tdr* ptr = NULL; // silence uninitialized warning
SLONG id_length, id;
SLONG id_length;
TraNumber id;

while (*p)
{
Expand All @@ -344,7 +345,7 @@ static tdr* get_description(ISC_QUAD* blob_id)

case TDR_TRANSACTION_ID:
id_length = *p++;
id = gds__vax_integer(reinterpret_cast<const UCHAR*>(p), id_length);
id = isc_portable_integer(reinterpret_cast<const UCHAR*>(p), id_length);
p += id_length;
if (!trans) {
trans = ptr = FB_NEW_POOL(*tdgbl->getDefaultPool()) tdr;
Expand Down
2 changes: 1 addition & 1 deletion src/alice/alice_meta.h
Original file line number Diff line number Diff line change
Expand Up @@ -26,7 +26,7 @@

void MET_disable_wal(ISC_STATUS*, isc_db_handle);
void MET_get_state(ISC_STATUS*, tdr*);
tdr* MET_get_transaction(ISC_STATUS*, isc_db_handle, SLONG);
tdr* MET_get_transaction(ISC_STATUS*, isc_db_handle, TraNumber);
void MET_set_capabilities(ISC_STATUS*, tdr*);

#endif // ALICE_ALICE_META_H
Expand Down
29 changes: 17 additions & 12 deletions src/alice/tdr.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -53,7 +53,7 @@ static SINT64 ask();
static void print_description(const tdr*);
static void reattach_database(tdr*);
static void reattach_databases(tdr*);
static bool reconnect(FB_API_HANDLE, SLONG, const TEXT*, SINT64);
static bool reconnect(FB_API_HANDLE, TraNumber, const TEXT*, SINT64);


static const UCHAR limbo_info[] = { isc_info_limbo, isc_info_end };
Expand Down Expand Up @@ -285,7 +285,7 @@ void TDR_list_limbo(FB_API_HANDLE handle, const TEXT* name, const SINT64 switche
return;
}

SLONG id;
TraNumber id;
tdr* trans;
UCHAR* ptr = buffer;
bool flag = true;
Expand All @@ -298,7 +298,7 @@ void TDR_list_limbo(FB_API_HANDLE handle, const TEXT* name, const SINT64 switche
switch (item)
{
case isc_info_limbo:
id = gds__vax_integer(ptr, length);
id = isc_portable_integer(ptr, length);
if (switches & (sw_commit | sw_rollback | sw_two_phase | sw_prompt))
{
TDR_reconnect_multiple(handle, id, name, switches);
Expand All @@ -312,16 +312,19 @@ void TDR_list_limbo(FB_API_HANDLE handle, const TEXT* name, const SINT64 switche
}
if (trans = MET_get_transaction(status_vector, handle, id))
{
tdgbl->uSvc->putSLong(isc_spb_multi_tra_id, id);
if (id > TraNumber(MAX_SLONG))
tdgbl->uSvc->putSInt64(isc_spb_multi_tra_id_64, id);
else
tdgbl->uSvc->putSLong(isc_spb_multi_tra_id, (SLONG) id);
reattach_databases(trans);
TDR_get_states(trans);
TDR_shutdown_databases(trans);
print_description(trans);
}
else if (id > TraNumber(MAX_SLONG))
tdgbl->uSvc->putSInt64(isc_spb_single_tra_id_64, id);
else
{
tdgbl->uSvc->putSLong(isc_spb_single_tra_id, id);
}
tdgbl->uSvc->putSLong(isc_spb_single_tra_id, (SLONG) id);
ptr += length;
break;

Expand Down Expand Up @@ -362,7 +365,7 @@ void TDR_list_limbo(FB_API_HANDLE handle, const TEXT* name, const SINT64 switche
// gfix user.
//

bool TDR_reconnect_multiple(FB_API_HANDLE handle, SLONG id, const TEXT* name, SINT64 switches)
bool TDR_reconnect_multiple(FB_API_HANDLE handle, TraNumber id, const TEXT* name, SINT64 switches)
{
ISC_STATUS_ARRAY status_vector;

Expand Down Expand Up @@ -531,7 +534,10 @@ static void print_description(const tdr* trans)
// msg 94: Transaction %ld
ALICE_print(94, SafeArg() << ptr->tdr_id);
}
tdgbl->uSvc->putSLong(isc_spb_tra_id, ptr->tdr_id);
if (ptr->tdr_id > TraNumber(MAX_SLONG))
tdgbl->uSvc->putSInt64(isc_spb_tra_id_64, ptr->tdr_id);
else
tdgbl->uSvc->putSLong(isc_spb_tra_id, (SLONG) ptr->tdr_id);
}

switch (ptr->tdr_state)
Expand Down Expand Up @@ -808,14 +814,13 @@ static void reattach_databases(tdr* trans)
// Commit or rollback a named transaction.
//

static bool reconnect(FB_API_HANDLE handle, SLONG number, const TEXT* name, SINT64 switches)
static bool reconnect(FB_API_HANDLE handle, TraNumber number, const TEXT* name, SINT64 switches)
{
ISC_STATUS_ARRAY status_vector;

const SLONG id = gds__vax_integer(reinterpret_cast<const UCHAR*>(&number), 4);
FB_API_HANDLE transaction = 0;
if (isc_reconnect_transaction(status_vector, &handle, &transaction,
sizeof(id), reinterpret_cast<const char*>(&id)))
sizeof(number), reinterpret_cast<const char*>(&number)))
{
ALICE_print(90, SafeArg() << name);
// msg 90: failed to reconnect to a transaction in database %s
Expand Down
2 changes: 1 addition & 1 deletion src/alice/tdr_proto.h
Original file line number Diff line number Diff line change
Expand Up @@ -25,7 +25,7 @@
#define ALICE_TDR_PROTO_H

void TDR_list_limbo(FB_API_HANDLE, const TEXT*, const SINT64);
bool TDR_reconnect_multiple(FB_API_HANDLE, SLONG, const TEXT*, SINT64);
bool TDR_reconnect_multiple(FB_API_HANDLE, TraNumber, const TEXT*, SINT64);
void TDR_shutdown_databases(tdr*);
USHORT TDR_analyze(const tdr*);
bool TDR_attach_database(ISC_STATUS*, tdr*, const TEXT*);
Expand Down
1 change: 1 addition & 0 deletions src/common/UtilSvc.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -134,6 +134,7 @@ class StandaloneUtilityInterface : public UtilSvc
virtual void started() { }
virtual void putLine(char, const char*) { }
virtual void putSLong(char, SLONG) { }
virtual void putSInt64(char, SINT64) { }
virtual void putChar(char, char) { }
virtual void putBytes(const UCHAR*, FB_SIZE_T) { }
virtual ULONG getBytes(UCHAR*, ULONG) { return 0; }
Expand Down
1 change: 1 addition & 0 deletions src/common/UtilSvc.h
Original file line number Diff line number Diff line change
Expand Up @@ -60,6 +60,7 @@ class UtilSvc : public Firebird::GlobalStorage
virtual void printf(bool err, const SCHAR* format, ...) = 0;
virtual void putLine(char, const char*) = 0;
virtual void putSLong(char, SLONG) = 0;
virtual void putSInt64(char, SINT64) = 0;
virtual void putChar(char, char) = 0;
virtual void putBytes(const UCHAR*, FB_SIZE_T) = 0;
virtual ULONG getBytes(UCHAR*, ULONG) = 0;
Expand Down
Loading

0 comments on commit 1ae6a9b

Please sign in to comment.