Skip to content

Commit

Permalink
Merge branch 'main' into tyler-no-schema-pragma
Browse files Browse the repository at this point in the history
  • Loading branch information
tylerkaraszewski committed Dec 18, 2024
2 parents 0aff705 + a03c2f3 commit 66442de
Show file tree
Hide file tree
Showing 12 changed files with 142 additions and 93 deletions.
15 changes: 11 additions & 4 deletions BedrockServer.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -97,7 +97,7 @@ void BedrockServer::sync()
// We use fewer FDs on test machines that have other resource restrictions in place.

SINFO("Setting dbPool size to: " << _dbPoolSize);
_dbPool = make_shared<SQLitePool>(_dbPoolSize, args["-db"], args.calc("-cacheSize"), args.calc("-maxJournalSize"), journalTables, mmapSizeGB, args.isSet("-hctree"));
_dbPool = make_shared<SQLitePool>(_dbPoolSize, args["-db"], args.calc("-cacheSize"), args.calc("-maxJournalSize"), journalTables, mmapSizeGB, args.isSet("-hctree"), args["-checkpointMode"]);
SQLite& db = _dbPool->getBase();

// Initialize the command processor.
Expand Down Expand Up @@ -358,7 +358,7 @@ void BedrockServer::sync()
committingCommand = true;
_syncNode->startCommit(SQLiteNode::QUORUM);
_lastQuorumCommandTime = STimeNow();

// This interrupts the next poll loop immediately. This prevents a 1-second wait when running as a single server.
_notifyDoneSync.push(true);
SDEBUG("Finished sending distributed transaction for db upgrade.");
Expand Down Expand Up @@ -1695,14 +1695,14 @@ void BedrockServer::_status(unique_ptr<BedrockCommand>& command) {
size_t totalCount = 0;
for (const auto& s : _crashCommands) {
totalCount += s.second.size();

vector<string> paramsArray;
for (const STable& params : s.second) {
if (!params.empty()) {
paramsArray.push_back(SComposeJSONObject(params));
}
}

STable commandObject;
commandObject[s.first] = SComposeJSONArray(paramsArray);
crashCommandListArray.push_back(SComposeJSONObject(commandObject));
Expand Down Expand Up @@ -1823,6 +1823,7 @@ atomic<bool> __quiesceShouldUnlock(false);
thread* __quiesceThread = nullptr;

void BedrockServer::_control(unique_ptr<BedrockCommand>& command) {
SINFO("Received control command: " << command->request.methodLine);
SData& response = command->response;
string reason = "MANUAL";
response.methodLine = "200 OK";
Expand Down Expand Up @@ -1913,7 +1914,9 @@ void BedrockServer::_control(unique_ptr<BedrockCommand>& command) {
if (dbPoolCopy) {
SQLiteScopedHandle dbScope(*_dbPool, _dbPool->getIndex());
SQLite& db = dbScope.db();
SINFO("[quiesce] Exclusive locking DB");
db.exclusiveLockDB();
SINFO("[quiesce] Exclusive locked DB");
locked = true;
while (true) {
if (__quiesceShouldUnlock) {
Expand All @@ -1936,12 +1939,16 @@ void BedrockServer::_control(unique_ptr<BedrockCommand>& command) {
response.methodLine = "200 Blocked";
}
} else if (SIEquals(command->request.methodLine, "UnblockWrites")) {
SINFO("[quiesce] Locking __quiesceLock");
lock_guard lock(__quiesceLock);
SINFO("[quiesce] __quiesceLock locked");
if (!__quiesceThread) {
response.methodLine = "200 Not Blocked";
} else {
__quiesceShouldUnlock = true;
SINFO("[quiesce] Joining __quiesceThread");
__quiesceThread->join();
SINFO("[quiesce] __quiesceThread joined");
delete __quiesceThread;
__quiesceThread = nullptr;
response.methodLine = "200 Unblocked";
Expand Down
36 changes: 24 additions & 12 deletions libstuff/sqlite3.c
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,7 @@
** separate file. This file contains only code for the core SQLite library.
**
** The content in this amalgamation comes from Fossil check-in
** 3c25c69c93e55738cdbfdd87fa3c879b8786.
** fa87355f6286be1e92f22a71cbfbfb13d1a4.
*/
#define SQLITE_CORE 1
#define SQLITE_AMALGAMATION 1
Expand Down Expand Up @@ -465,7 +465,7 @@ extern "C" {
*/
#define SQLITE_VERSION "3.47.0"
#define SQLITE_VERSION_NUMBER 3047000
#define SQLITE_SOURCE_ID "2024-12-12 20:39:56 3c25c69c93e55738cdbfdd87fa3c879b878674973955490770f5e274da1ca9a4"
#define SQLITE_SOURCE_ID "2024-12-13 18:13:51 fa87355f6286be1e92f22a71cbfbfb13d1a478d5fb5b38abedbd78bf903171fa"

/*
** CAPI3REF: Run-Time Library Version Numbers
Expand Down Expand Up @@ -18241,13 +18241,14 @@ struct sqlite3 {
#define SCHEMA_TIME_STAT4_Q1_BODY 14
#define SCHEMA_TIME_AFTER_STAT4_Q1 15
#define SCHEMA_TIME_STAT4_Q2_BODY 16
#define SCHEMA_TIME_AFTER_STAT4_Q2 17
#define SCHEMA_TIME_AFTER_STAT4 18
#define SCHEMA_TIME_STAT4_SAMPLE_MALLOC 17
#define SCHEMA_TIME_AFTER_STAT4_Q2 18
#define SCHEMA_TIME_AFTER_STAT4 19

#define SCHEMA_TIME_END_ANALYZE_LOAD 19
#define SCHEMA_TIME_FINISH 20
#define SCHEMA_TIME_END_ANALYZE_LOAD 20
#define SCHEMA_TIME_FINISH 21

#define SCHEMA_TIME_N 21
#define SCHEMA_TIME_N 22
#define SCHEMA_TIME_TIMEOUT (500 * 1000)


Expand Down Expand Up @@ -93491,7 +93492,7 @@ SQLITE_PRIVATE void sqlite3CommitTimeLog(u64 *aCommit){
}
zStr = sqlite3_mprintf("%z%s%s%d%s", zStr, (zStr?", ":""),zHash,iVal,zU);
}
sqlite3_log(SQLITE_WARNING, "slow commit (v=18): (%s)", zStr);
sqlite3_log(SQLITE_WARNING, "slow commit (v=19): (%s)", zStr);
sqlite3_free(zStr);
}
}
Expand Down Expand Up @@ -93519,7 +93520,7 @@ SQLITE_PRIVATE void sqlite3PrepareTimeLog(const char *zSql, int nSql, u64 *aPrep
}
if( nByte<0 ){ nByte = sqlite3Strlen30(zSql); }
sqlite3_log(SQLITE_WARNING,
"slow prepare (v=18): (%s) [%.*s]", zStr, nByte, zSql
"slow prepare (v=19): (%s) [%.*s]", zStr, nByte, zSql
);
sqlite3_free(zStr);
}
Expand All @@ -93535,12 +93536,13 @@ SQLITE_PRIVATE void sqlite3SchemaTimeLog(u64 *aSchema, const char *zFile){
if( val!=0
&& ii!=SCHEMA_TIME_STAT4_Q1_BODY
&& ii!=SCHEMA_TIME_STAT4_Q2_BODY
&& ii!=SCHEMA_TIME_STAT4_SAMPLE_MALLOC
){
val -= i1;
}
zStr = sqlite3_mprintf("%z%s%d", zStr, (zStr?", ":""), val);
}
sqlite3_log(SQLITE_WARNING, "slow schema (%s) (v=18): (%s)", zFile, zStr);
sqlite3_log(SQLITE_WARNING, "slow schema (%s) (v=19): (%s)", zFile, zStr);
sqlite3_free(zStr);
}
}
Expand Down Expand Up @@ -123568,6 +123570,9 @@ static void decodeIntArray(
#endif
if( *z==' ' ) z++;
}
if( aOut ){
for(/* no-op */; i<nOut; i++){ aOut[i] = 0; }
}
#ifndef SQLITE_ENABLE_STAT4
assert( pIndex!=0 ); {
#else
Expand Down Expand Up @@ -123792,6 +123797,7 @@ static int growSampleArray(sqlite3 *db, Index *pIdx){
tRowcnt *pSpace; /* Available allocated memory space */
u8 *pPtr; /* Available memory as a u8 for easier manipulation */
int i;
u64 t;

/* In production set the initial allocation to SQLITE_STAT4_SAMPLES. This
** means that reallocation will almost never be required. But for debug
Expand All @@ -123811,8 +123817,14 @@ static int growSampleArray(sqlite3 *db, Index *pIdx){
nByte += sizeof(tRowcnt) * nIdxCol * 3 * nNew;
nByte += nIdxCol * sizeof(tRowcnt); /* Space for Index.aAvgEq[] */

aNew = (IndexSample*)sqlite3DbMallocZero(db, nByte);
if( db->aSchemaTime ){
t = sqlite3STimeNow();
}
aNew = (IndexSample*)sqlite3DbMallocRaw(db, nByte);
if( aNew==0 ) return SQLITE_NOMEM_BKPT;
if( db->aSchemaTime ){
db->aSchemaTime[SCHEMA_TIME_STAT4_SAMPLE_MALLOC] += (sqlite3STimeNow() - t);
}

pPtr = (u8*)aNew;
pPtr += ROUND8(nNew*sizeof(pIdx->aSample[0]));
Expand Down Expand Up @@ -258017,7 +258029,7 @@ static void fts5SourceIdFunc(
){
assert( nArg==0 );
UNUSED_PARAM2(nArg, apUnused);
sqlite3_result_text(pCtx, "fts5: 2024-12-12 20:39:56 3c25c69c93e55738cdbfdd87fa3c879b878674973955490770f5e274da1ca9a4", -1, SQLITE_TRANSIENT);
sqlite3_result_text(pCtx, "fts5: 2024-12-13 18:13:51 fa87355f6286be1e92f22a71cbfbfb13d1a478d5fb5b38abedbd78bf903171fa", -1, SQLITE_TRANSIENT);
}

/*
Expand Down
2 changes: 1 addition & 1 deletion libstuff/sqlite3.h
Original file line number Diff line number Diff line change
Expand Up @@ -148,7 +148,7 @@ extern "C" {
*/
#define SQLITE_VERSION "3.47.0"
#define SQLITE_VERSION_NUMBER 3047000
#define SQLITE_SOURCE_ID "2024-12-12 20:39:56 3c25c69c93e55738cdbfdd87fa3c879b878674973955490770f5e274da1ca9a4"
#define SQLITE_SOURCE_ID "2024-12-13 18:13:51 fa87355f6286be1e92f22a71cbfbfb13d1a478d5fb5b38abedbd78bf903171fa"

/*
** CAPI3REF: Run-Time Library Version Numbers
Expand Down
4 changes: 4 additions & 0 deletions main.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -236,6 +236,7 @@ int main(int argc, char* argv[]) {
<< endl;
cout << "-maxJournalSize <#commits> Number of commits to retain in the historical journal (default 1000000)"
<< endl;
cout << "-checkpointMode <mode> Accepts PASSIVE|FULL|RESTART|TRUNCATE, which is the value passed to https://www.sqlite.org/c3ref/wal_checkpoint_v2.html" << endl;
cout << endl;
cout << "Quick Start Tips:" << endl;
cout << "-----------------" << endl;
Expand Down Expand Up @@ -300,6 +301,9 @@ int main(int argc, char* argv[]) {
SETDEFAULT("-queryLog", "queryLog.csv");
SETDEFAULT("-enableMultiWrite", "true");

// We default to PASSIVE checkpoint everywhere as that has been the value proven to work fine for many years.
SETDEFAULT("-checkpointMode", "PASSIVE");

args["-plugins"] = SComposeList(loadPlugins(args));

// Reset the database if requested
Expand Down
Loading

0 comments on commit 66442de

Please sign in to comment.