Skip to content

Commit

Permalink
Wipe out multi-file database support (#8047)
Browse files Browse the repository at this point in the history
* Wipe out multi-file database support

* Fix (fingers crossed) Windows build, some more cleanup and code simplification

* Fix gstat build on Windows and also Android/MacOS builds
  • Loading branch information
dyemanov authored Dec 28, 2024
1 parent 1251401 commit f0740d2
Show file tree
Hide file tree
Showing 22 changed files with 375 additions and 1,495 deletions.
108 changes: 70 additions & 38 deletions src/burp/restore.epp
Original file line number Diff line number Diff line change
Expand Up @@ -4204,53 +4204,85 @@ bool get_files(BurpGlobals* tdgbl)
att_type attribute;
scan_attr_t scan_next_attr;

STORE (REQUEST_HANDLE tdgbl->handles_get_files_req_handle1)
X IN RDB$FILES
X.RDB$FILE_FLAGS = 0;
BASED_ON RDB$FILES.RDB$FILE_NAME filename = "";
SSHORT flags = 0, sequence = 0, number = 0;
SLONG start = 0, length = 0;

skip_init(&scan_next_attr);
while (skip_scan(&scan_next_attr), get_attribute(&attribute, tdgbl) != att_end)
skip_init(&scan_next_attr);
while (skip_scan(&scan_next_attr), get_attribute(&attribute, tdgbl) != att_end)
{
switch (attribute)
{
switch (attribute)
{
case att_file_filename:
GET_TEXT(X.RDB$FILE_NAME);
BURP_verbose (116, X.RDB$FILE_NAME);
// msg 116 restoring file %s
break;
case att_file_filename:
GET_TEXT(filename);
break;

case att_file_sequence:
X.RDB$FILE_SEQUENCE = (USHORT) get_int32(tdgbl);
break;
case att_file_sequence:
sequence = (SSHORT) get_int32(tdgbl);
break;

case att_file_start:
X.RDB$FILE_START = get_int32(tdgbl);
break;
case att_file_start:
start = get_int32(tdgbl);
break;

case att_file_length:
X.RDB$FILE_LENGTH = get_int32(tdgbl);
break;
case att_file_length:
length = get_int32(tdgbl);
break;

case att_file_flags:
X.RDB$FILE_FLAGS |= get_int32(tdgbl);
break;
case att_file_flags:
flags |= (SSHORT) get_int32(tdgbl);
break;

case att_shadow_number:
X.RDB$SHADOW_NUMBER = (USHORT) get_int32(tdgbl);
if (tdgbl->gbl_sw_kill && X.RDB$SHADOW_NUMBER)
X.RDB$FILE_FLAGS |= FILE_inactive;
break;
case att_shadow_number:
number = (SSHORT) get_int32(tdgbl);
if (tdgbl->gbl_sw_kill && number)
flags |= FILE_inactive;
break;

default:
bad_attribute(scan_next_attr, attribute, 85);
// msg 85 file
break;
}
default:
bad_attribute(scan_next_attr, attribute, 85);
// msg 85 file
break;
}
END_STORE;
ON_ERROR
general_on_error ();
END_ERROR;
}

const bool multiFileSupport = (tdgbl->runtimeODS <= DB_VERSION_DDL13_1);

if ((multiFileSupport || !sequence) && filename[0])
{
BURP_verbose (116, filename);
// msg 116 restoring file %s

STORE (REQUEST_HANDLE tdgbl->handles_get_files_req_handle1)
X IN RDB$FILES

strncpy(X.RDB$FILE_NAME, filename, sizeof(X.RDB$FILE_NAME));
X.RDB$FILE_FLAGS = flags;
X.RDB$SHADOW_NUMBER = number;

if (multiFileSupport)
{
X.RDB$FILE_SEQUENCE.NULL = FALSE;
X.RDB$FILE_SEQUENCE = sequence;

X.RDB$FILE_START.NULL = FALSE;
X.RDB$FILE_START = start;

X.RDB$FILE_LENGTH.NULL = FALSE;
X.RDB$FILE_LENGTH = length;
}
else
{
X.RDB$FILE_SEQUENCE.NULL = TRUE;
X.RDB$FILE_START.NULL = TRUE;
X.RDB$FILE_LENGTH.NULL = TRUE;
}

END_STORE;
ON_ERROR
general_on_error ();
END_ERROR;
}

return true;
}
Expand Down
100 changes: 25 additions & 75 deletions src/dsql/DdlNodes.epp
Original file line number Diff line number Diff line change
Expand Up @@ -80,9 +80,6 @@ static void defineComputed(DsqlCompilerScratch* dsqlScratch, RelationSourceNode*
dsql_fld* field, ValueSourceClause* clause, string& source, BlrDebugWriter::BlrData& value);
static void deleteKeyConstraint(thread_db* tdbb, jrd_tra* transaction,
const MetaName& relationName, const MetaName& constraintName, const MetaName& indexName);
static void defineFile(thread_db* tdbb, jrd_tra* transaction, SLONG shadowNumber, bool manualShadow,
bool conditionalShadow, SLONG& dbAlloc,
const PathName& name, SLONG start, SLONG length);
static bool fieldExists(thread_db* tdbb, jrd_tra* transaction, const MetaName& relationName,
const MetaName& fieldName);
static bool isItSqlRole(thread_db* tdbb, jrd_tra* transaction, const MetaName& inputName,
Expand Down Expand Up @@ -490,46 +487,6 @@ static void deleteKeyConstraint(thread_db* tdbb, jrd_tra* transaction,
}
}

// Define a database or shadow file.
static void defineFile(thread_db* tdbb, jrd_tra* transaction, SLONG shadowNumber, bool manualShadow,
bool conditionalShadow, SLONG& dbAlloc, const PathName& name, SLONG start, SLONG length)
{
PathName expandedName = name;

if (!ISC_expand_filename(expandedName, false))
status_exception::raise(Arg::PrivateDyn(231)); // File name is invalid.

if (tdbb->getDatabase()->dbb_filename == expandedName)
status_exception::raise(Arg::PrivateDyn(166));

AutoCacheRequest request(tdbb, drq_l_files, DYN_REQUESTS);

FOR(REQUEST_HANDLE request TRANSACTION_HANDLE transaction)
FIRST 1 X IN RDB$FILES
WITH X.RDB$FILE_NAME EQ expandedName.c_str()
{
status_exception::raise(Arg::PrivateDyn(166));
}
END_FOR

request.reset(tdbb, drq_s_files, DYN_REQUESTS);

STORE(REQUEST_HANDLE request TRANSACTION_HANDLE transaction)
X IN RDB$FILES
{
expandedName.copyTo(X.RDB$FILE_NAME, sizeof(X.RDB$FILE_NAME));
X.RDB$SHADOW_NUMBER = shadowNumber;
X.RDB$FILE_FLAGS = (manualShadow ? FILE_manual : 0) |
(conditionalShadow ? FILE_conditional : 0);

dbAlloc = MAX(dbAlloc, start);
X.RDB$FILE_START = dbAlloc;
X.RDB$FILE_LENGTH = length;
dbAlloc += length;
}
END_STORE
}

// Checks to see if the given field already exists in a relation.
static bool fieldExists(thread_db* tdbb, jrd_tra* transaction, const MetaName& relationName,
const MetaName& fieldName)
Expand Down Expand Up @@ -10462,7 +10419,7 @@ string CreateShadowNode::internalPrint(NodePrinter& printer) const
NODE_PRINT(printer, number);
NODE_PRINT(printer, manual);
NODE_PRINT(printer, conditional);
NODE_PRINT(printer, files);
NODE_PRINT(printer, fileName);

return "CreateShadowNode";
}
Expand All @@ -10486,7 +10443,7 @@ void CreateShadowNode::execute(thread_db* tdbb, DsqlCompilerScratch* /*dsqlScrat
// run all statements under savepoint control
AutoSavePoint savePoint(tdbb, transaction);

// If a shadow set identified by the shadow number already exists return error.
// If a shadow set identified by the shadow number already exists return error

AutoCacheRequest request(tdbb, drq_l_shadow, DYN_REQUESTS);

Expand All @@ -10502,25 +10459,34 @@ void CreateShadowNode::execute(thread_db* tdbb, DsqlCompilerScratch* /*dsqlScrat
}
END_FOR

SLONG start = 0;
PathName expandedName = fileName.ToPathName();

for (NestConst<DbFileClause>* i = files.begin(); i != files.end(); ++i)
if (!ISC_expand_filename(expandedName, false))
status_exception::raise(Arg::PrivateDyn(231)); // File name is invalid

if (tdbb->getDatabase()->dbb_filename == expandedName)
status_exception::raise(Arg::PrivateDyn(166));

request.reset(tdbb, drq_l_files, DYN_REQUESTS);

FOR(REQUEST_HANDLE request TRANSACTION_HANDLE transaction)
FIRST 1 X IN RDB$FILES
WITH X.RDB$FILE_NAME EQ expandedName.c_str()
{
bool first = i == files.begin();
DbFileClause* file = *i;
status_exception::raise(Arg::PrivateDyn(166));
}
END_FOR

if (!first && i[-1]->length == 0 && file->start == 0)
{
// Preceding file did not specify length, so %s must include starting page number
status_exception::raise(
Arg::Gds(isc_sqlerr) << Arg::Num(-607) <<
Arg::Gds(isc_dsql_command_err) <<
Arg::Gds(isc_dsql_file_length_err) << file->name);
}
request.reset(tdbb, drq_s_files, DYN_REQUESTS);

defineFile(tdbb, transaction, number, manual && first, conditional && first,
start, file->name.c_str(), file->start, file->length);
STORE(REQUEST_HANDLE request TRANSACTION_HANDLE transaction)
X IN RDB$FILES
{
expandedName.copyTo(X.RDB$FILE_NAME, sizeof(X.RDB$FILE_NAME));
X.RDB$SHADOW_NUMBER = number;
X.RDB$FILE_FLAGS = (manual ? FILE_manual : 0) | (conditional ? FILE_conditional : 0);
}
END_STORE

savePoint.release(); // everything is ok
}
Expand Down Expand Up @@ -12742,13 +12708,11 @@ string AlterDatabaseNode::internalPrint(NodePrinter& printer) const
DdlNode::internalPrint(printer);

NODE_PRINT(printer, create);
NODE_PRINT(printer, createLength);
NODE_PRINT(printer, linger);
NODE_PRINT(printer, clauses);
NODE_PRINT(printer, differenceFile);
NODE_PRINT(printer, setDefaultCharSet);
NODE_PRINT(printer, setDefaultCollation);
NODE_PRINT(printer, files);
NODE_PRINT(printer, cryptPlugin);
NODE_PRINT(printer, keyName);

Expand Down Expand Up @@ -12924,18 +12888,6 @@ void AlterDatabaseNode::execute(thread_db* tdbb, DsqlCompilerScratch* dsqlScratc
}
}

SLONG dbAlloc = PageSpace::maxAlloc(tdbb->getDatabase());
SLONG start = create ? createLength + 1 : 0;
for (NestConst<DbFileClause>* i = files.begin(); i != files.end(); ++i)
{
DbFileClause* file = *i;

start = MAX(start, file->start);
defineFile(tdbb, transaction, 0, false, false, dbAlloc,
file->name.c_str(), start, file->length);
start += file->length;
}

if (differenceFile.hasData())
defineDifference(tdbb, transaction, differenceFile.c_str());

Expand Down Expand Up @@ -13064,7 +13016,6 @@ void AlterDatabaseNode::changeBackupMode(thread_db* tdbb, jrd_tra* transaction,
X IN RDB$FILES
{
X.RDB$FILE_FLAGS = FILE_difference | FILE_backing_up;
X.RDB$FILE_START = 0;
}
END_STORE

Expand Down Expand Up @@ -13116,7 +13067,6 @@ void AlterDatabaseNode::defineDifference(thread_db* tdbb, jrd_tra* transaction,

strcpy(FIL.RDB$FILE_NAME, file.c_str());
FIL.RDB$FILE_FLAGS = FILE_difference;
FIL.RDB$FILE_START = 0;
}
END_STORE
}
Expand Down
57 changes: 9 additions & 48 deletions src/dsql/DdlNodes.h
Original file line number Diff line number Diff line change
Expand Up @@ -101,40 +101,6 @@ class ValueSourceClause : public Printable
};


class DbFileClause : public Printable
{
public:
DbFileClause(MemoryPool& p, const DbFileClause& o)
: name(p, o.name),
start(o.start),
length(o.length)
{
}

explicit DbFileClause(MemoryPool& p, const Firebird::string& aName)
: name(p, aName),
start(0),
length(0)
{
}

public:
virtual Firebird::string internalPrint(NodePrinter& printer) const
{
NODE_PRINT(printer, name);
NODE_PRINT(printer, start);
NODE_PRINT(printer, length);

return "DbFileClause";
}

public:
Firebird::string name; // File name
SLONG start; // Starting page
SLONG length; // File length in pages
};


class ExternalClause : public Printable
{
public:
Expand Down Expand Up @@ -1967,12 +1933,13 @@ class DropFilterNode : public DdlNode
class CreateShadowNode : public DdlNode
{
public:
CreateShadowNode(MemoryPool& p, const SSHORT aNumber)
CreateShadowNode(MemoryPool& p, SSHORT aNumber, bool aManual, bool aConditional,
const Firebird::string& aFileName)
: DdlNode(p),
number(aNumber),
manual(false),
conditional(false),
files(p)
manual(aManual),
conditional(aConditional),
fileName(p, aFileName)
{
}

Expand All @@ -1996,7 +1963,7 @@ class CreateShadowNode : public DdlNode
SSHORT number;
bool manual;
bool conditional;
Firebird::Array<NestConst<DbFileClause> > files;
Firebird::string fileName;
bool createIfNotExistsOnly = false;
};

Expand Down Expand Up @@ -2425,14 +2392,9 @@ class AlterDatabaseNode : public DdlNode
public:
AlterDatabaseNode(MemoryPool& p)
: DdlNode(p),
create(false),
createLength(0),
linger(-1),
clauses(0),
differenceFile(p),
setDefaultCharSet(p),
setDefaultCollation(p),
files(p),
cryptPlugin(p),
keyName(p),
pubTables(p)
Expand Down Expand Up @@ -2468,13 +2430,12 @@ class AlterDatabaseNode : public DdlNode
void checkClauses(thread_db* tdbb);

public:
bool create; // Is the node created with a CREATE DATABASE command?
SLONG createLength, linger;
unsigned clauses;
bool create = false; // Is the node created with a CREATE DATABASE command?
SLONG linger = -1;
unsigned clauses = 0;
Firebird::string differenceFile;
MetaName setDefaultCharSet;
MetaName setDefaultCollation;
Firebird::Array<NestConst<DbFileClause> > files;
MetaName cryptPlugin;
MetaName keyName;
Firebird::TriState ssDefiner;
Expand Down
Loading

0 comments on commit f0740d2

Please sign in to comment.