Skip to content

Commit

Permalink
refactoring and comments
Browse files Browse the repository at this point in the history
  • Loading branch information
mlin committed May 23, 2021
1 parent e81ef25 commit 85af802
Show file tree
Hide file tree
Showing 2 changed files with 17 additions and 14 deletions.
19 changes: 15 additions & 4 deletions src/SQLiteNestedVFS.h
Original file line number Diff line number Diff line change
Expand Up @@ -206,6 +206,8 @@ class InnerDatabaseFile : public SQLiteVFS::File {

// reset the outer database cursor; should be done when it otherwise might go stale.
virtual void ResetCursor() {
src = nullptr;
src_size = 0;
if (cursor_pageno > 0) {
cursor.reset();
cursor_pageno = 0;
Expand Down Expand Up @@ -241,18 +243,23 @@ class InnerDatabaseFile : public SQLiteVFS::File {
}
cursor_pageno = pageno;
}
SQLite::Column data = cursor.getColumn(1);
auto data = cursor.getColumn(1);
assert(data.getName() == std::string("data"));
src = data.getBlob();
src_size = data.getBytes();
if (src_size && (!src || !data.isBlob())) {
throw SQLite::Exception("corrupt page " + std::to_string(pageno), SQLITE_CORRUPT);
}
FinishSeek();
#ifndef NDEBUG
t_seek += std::chrono::high_resolution_clock::now() - t0;
#endif
}

// Override to add additional logic after seeking cursor (still under the seek lock), such
// as reading the meta columns.
virtual void FinishSeek() {}

// Decode one page from the blob stored in the outer db. Override me!
// May parallelize with other jobs.
virtual void DecodePage() {
Expand Down Expand Up @@ -702,7 +709,7 @@ class InnerDatabaseFile : public SQLiteVFS::File {
// into a special row with pageno = -100.
upsert->reset();
upsert->bindNoCopy(1, job->encoded_page,
std::min(job->encoded_page_size, size_t(100)));
std::min(job->encoded_page_size, size_t(100)));
// keep meta1 & meta2 bindings, if any
upsert->bind(4, (sqlite_int64)-100);
if (upsert->exec() != 1) {
Expand Down Expand Up @@ -1035,10 +1042,11 @@ class VFS : public SQLiteVFS::Wrapper {
if (zName && zName[0]) {
std::string sName(zName);
if (flags & SQLITE_OPEN_MAIN_DB) {
// strip inner_db_filename_suffix_ to get filename of outer database
std::string outer_db_filename = sName;
bool web = sName == "/__web__";
if (!web) {
// strip inner_db_filename_suffix_ to get filename of outer database (see
// FullPathname below)
if (sName.size() > inner_db_filename_suffix_.size()) {
outer_db_filename =
sName.substr(0, sName.size() - inner_db_filename_suffix_.size());
Expand All @@ -1057,6 +1065,7 @@ class VFS : public SQLiteVFS::Wrapper {
std::string outer_db_uri = "file:" + urlencode(outer_db_filename, true);
bool unsafe = sqlite3_uri_boolean(zName, "outer_unsafe", 0);
if (web) {
// use sqlite_web_vfs, passing through configuration
outer_db_uri += "?immutable=1";
for (const char *passthrough : {"web_log", "web_insecure", "web_url"}) {
if (sqlite3_uri_parameter(zName, passthrough)) {
Expand Down Expand Up @@ -1154,10 +1163,12 @@ class VFS : public SQLiteVFS::Wrapper {

// Given user-provided db filename, use it as the outer db on the host filesystem, and
// append a suffix as the inner db's filename (which won't actually exist on the host
// filesystem, but xOpen() will recognize).
// filesystem, but xOpen() will recognize). This ensures the inner & outer journals will have
// distinct filenames.
int FullPathname(const char *zName, int nPathOut, char *zPathOut) override {
std::string zName2(zName);
if (zName2 == "/__web__") {
// unnecessary for read-only web access
strncpy(zPathOut, zName, nPathOut);
return SQLITE_OK;
}
Expand Down
12 changes: 2 additions & 10 deletions src/zstd_vfs.h
Original file line number Diff line number Diff line change
Expand Up @@ -122,13 +122,8 @@ class ZstdInnerDatabaseFile : public SQLiteNested::InnerDatabaseFile {
}

// After superclass seeks to a page, make sure we have the necessary decompression
// dictionary ready for use. This has to be done in this serialized method since it may
// need to load it from the outer db.
void SeekCursor() override {
super::FetchJob::SeekCursor();
#ifndef NDEBUG
auto t0 = std::chrono::high_resolution_clock::now();
#endif
// dictionary ready for use.
void FinishSeek() override {
ddict = nullptr;
plain = false;
auto meta1 = cursor.getColumn(2);
Expand All @@ -142,9 +137,6 @@ class ZstdInnerDatabaseFile : public SQLiteNested::InnerDatabaseFile {
throw SQLite::Exception("unexpected meta1 entry in zstd page table",
SQLITE_CORRUPT);
}
#ifndef NDEBUG
t_seek += std::chrono::high_resolution_clock::now() - t0;
#endif
}

// Perform decompression using dctx & ddict
Expand Down

0 comments on commit 85af802

Please sign in to comment.