Skip to content

Commit abe9759

Browse files
authored
Merge pull request #2135 from couchbase/merge/3.2_master
Merge 3.2.0 into master.
2 parents 8009302 + f00ef2c commit abe9759

File tree

8 files changed

+48
-17
lines changed

8 files changed

+48
-17
lines changed

C/include/c4DatabaseTypes.h

Lines changed: 8 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -31,13 +31,14 @@ C4API_BEGIN_DECLS
3131

3232
/** Boolean options for C4DatabaseConfig. */
3333
typedef C4_OPTIONS(uint32_t, C4DatabaseFlags){
34-
kC4DB_Create = 0x01, ///< Create the file if it doesn't exist
35-
kC4DB_ReadOnly = 0x02, ///< Open file read-only
36-
kC4DB_AutoCompact = 0x04, ///< Enable auto-compaction [UNIMPLEMENTED]
37-
kC4DB_VersionVectors = 0x08, ///< Upgrade DB to version vectors instead of rev trees
38-
kC4DB_NoUpgrade = 0x20, ///< Disable upgrading an older-version database
39-
kC4DB_NonObservable = 0x40, ///< Disable database/collection observers, for slightly faster writes
40-
kC4DB_FakeVectorClock = 0x80, ///< Use counters instead of timestamps in version vectors (TESTS ONLY)
34+
kC4DB_Create = 0x01, ///< Create the file if it doesn't exist
35+
kC4DB_ReadOnly = 0x02, ///< Open file read-only
36+
kC4DB_AutoCompact = 0x04, ///< Enable auto-compaction [UNIMPLEMENTED]
37+
kC4DB_VersionVectors = 0x08, ///< Upgrade DB to version vectors instead of rev trees
38+
kC4DB_NoUpgrade = 0x20, ///< Disable upgrading an older-version database
39+
kC4DB_NonObservable = 0x40, ///< Disable database/collection observers, for slightly faster writes
40+
kC4DB_DiskSyncFull = 0x80, ///< Flush to disk after each transaction
41+
kC4DB_FakeVectorClock = 0x0100, ///< Use counters instead of timestamps in version vectors (TESTS ONLY)
4142
};
4243

4344

LiteCore/Database/DatabaseImpl.cc

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -132,6 +132,7 @@ namespace litecore {
132132
options.create = (_config.flags & kC4DB_Create) != 0;
133133
options.writeable = (_config.flags & kC4DB_ReadOnly) == 0;
134134
options.upgradeable = (_config.flags & kC4DB_NoUpgrade) == 0;
135+
options.diskSyncFull = (_config.flags & kC4DB_DiskSyncFull) != 0;
135136
options.useDocumentKeys = true;
136137
options.encryptionAlgorithm = (EncryptionAlgorithm)_config.encryptionKey.algorithm;
137138
if ( options.encryptionAlgorithm != kNoEncryption ) {

LiteCore/Storage/DataFile.cc

Lines changed: 3 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -123,11 +123,9 @@ namespace litecore {
123123

124124

125125
const DataFile::Options DataFile::Options::defaults = {
126-
{true}, // sequences
127-
true,
128-
true,
129-
true,
130-
true // create, writeable, useDocumentKeys, upgradeable
126+
{true}, // sequences
127+
true, true, true, true, // create, writeable, useDocumentKeys, upgradeable
128+
false // diskSyncFull
131129
};
132130

133131
DataFile::DataFile(const FilePath& path, Delegate* delegate, const DataFile::Options* options)

LiteCore/Storage/DataFile.hh

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -75,6 +75,7 @@ namespace litecore {
7575
bool writeable : 1; ///< If false, db is opened read-only
7676
bool useDocumentKeys : 1; ///< Use SharedKeys for Fleece docs
7777
bool upgradeable : 1; ///< DB schema can be upgraded
78+
bool diskSyncFull : 1; ///< SQLite PRAGMA synchronous
7879
EncryptionAlgorithm encryptionAlgorithm; ///< What encryption (if any)
7980
alloc_slice encryptionKey; ///< Encryption key, if encrypting
8081
DatabaseTag dbTag;
@@ -273,6 +274,8 @@ namespace litecore {
273274

274275
void setOptions(const Options& o) { _options = o; }
275276

277+
const Options& getOptions() const { return _options; }
278+
276279
void forOpenKeyStores(function_ref<void(KeyStore&)> fn);
277280

278281
virtual Factory& factory() const = 0;

LiteCore/Storage/KeyStore.hh

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -11,7 +11,9 @@
1111
//
1212

1313
#pragma once
14-
#define LITECORE_CPP_API 1
14+
#ifndef LITECORE_CPP_API
15+
# define LITECORE_CPP_API 1
16+
#endif
1517
#include "IndexSpec.hh"
1618
#include "RecordEnumerator.hh"
1719
#include <optional>

LiteCore/Storage/SQLiteDataFile.cc

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -303,11 +303,12 @@ namespace litecore {
303303
_exec(stringprintf(
304304
"PRAGMA cache_size=%d; " // Memory cache
305305
"PRAGMA mmap_size=%d; " // Memory-mapped reads
306-
"PRAGMA synchronous=normal; " // Speeds up commits
306+
"PRAGMA synchronous=%s; " // Speeds up commits
307307
"PRAGMA journal_size_limit=%lld; " // Limit WAL disk usage
308308
"PRAGMA case_sensitive_like=true; " // Case sensitive LIKE, for N1QL compat
309309
"PRAGMA fullfsync=ON", // Attempt to mitigate damage due to sudden loss of power (iOS / macOS)
310-
-(int)kCacheSize / 1024, kMMapSize, (long long)kJournalSize));
310+
-(int)kCacheSize / 1024, kMMapSize, getOptions().diskSyncFull ? "full" : "normal",
311+
(long long)kJournalSize));
311312

312313
(void)upgradeSchema(SchemaVersion::WithPurgeCount, "Adding purgeCnt column", [&] {
313314
// Schema upgrade: Add the `purgeCnt` column to the kvmeta table.

LiteCore/tests/c4BaseTest.cc

Lines changed: 25 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -15,6 +15,7 @@
1515
#include "c4ExceptionUtils.hh"
1616
#include "fleece/InstanceCounted.hh"
1717
#include "catch.hpp"
18+
#include "DatabaseImpl.hh"
1819
#include "NumConversion.hh"
1920
#include "Actor.hh"
2021
#include "URLTransformer.hh"
@@ -25,6 +26,7 @@
2526
# include "Error.hh"
2627
# include <winerror.h>
2728
#endif
29+
#include <sstream>
2830

2931
using namespace fleece;
3032
using namespace std;
@@ -138,6 +140,29 @@ TEST_CASE("C4Error Reporting Macros", "[Errors][C]") {
138140
#endif
139141
}
140142

143+
TEST_CASE_METHOD(C4Test, "Database Flag FullSync", "[Database][C]") {
144+
// Ensure that, by default, diskSyncFull is false.
145+
CHECK(!litecore::asInternal(db)->dataFile()->options().diskSyncFull);
146+
147+
C4DatabaseConfig2 config = *c4db_getConfig2(db);
148+
config.flags |= kC4DB_DiskSyncFull;
149+
150+
std::stringstream ss;
151+
ss << std::string(c4db_getName(db)) << "_" << c4_now();
152+
c4::ref<C4Database> dbWithFullSync = c4db_openNamed(slice(ss.str().c_str()), &config, ERROR_INFO());
153+
// The flag in config is passed to DataFile options.
154+
CHECK(litecore::asInternal(dbWithFullSync)->dataFile()->options().diskSyncFull);
155+
156+
config.flags &= ~kC4DB_DiskSyncFull;
157+
c4::ref<C4Database> otherConnection = c4db_openNamed(c4db_getName(dbWithFullSync), &config, ERROR_INFO());
158+
// The flag applies per connection opened with the config.
159+
CHECK(!litecore::asInternal(otherConnection)->dataFile()->options().diskSyncFull);
160+
161+
c4::ref<C4Database> againConnection = c4db_openAgain(dbWithFullSync, ERROR_INFO());
162+
// The flag is passed to database opened by openAgain.
163+
CHECK(litecore::asInternal(againConnection)->dataFile()->options().diskSyncFull);
164+
}
165+
141166
#pragma mark - INSTANCECOUNTED:
142167

143168
namespace {

Networking/HTTP/HTTPLogic.cc

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -94,8 +94,8 @@ namespace litecore::net {
9494
// the new type can be handled the same way.
9595
if ( _isWebSocket ) {
9696
Address address = {_address.scheme() == "wss"_sl ? "https"_sl : "http"_sl, _address.hostname(),
97-
_address.port(), _address.url()};
98-
rq << string(Address::toURL(*(C4Address*)&address));
97+
_address.port(), _address.path()};
98+
rq << string(Address::toURL(*(C4Address*)address));
9999
} else {
100100
rq << string(_address.url());
101101
}

0 commit comments

Comments
 (0)