Skip to content

Commit

Permalink
Remove lite mode status in shared basic config
Browse files Browse the repository at this point in the history
  • Loading branch information
Qiuwen-chen committed Oct 24, 2024
1 parent 47279a6 commit 88095f6
Show file tree
Hide file tree
Showing 5 changed files with 15 additions and 22 deletions.
7 changes: 1 addition & 6 deletions src/common/core/InnerDatabase.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -247,11 +247,6 @@ void InnerDatabase::setLiteModeEnable(bool enable)
close([&] {
m_liteModeEnable = enable;
CommonCore::shared().enableAutoCheckpoint(this, !m_liteModeEnable);
auto config = m_configs.find(BasicConfigName);
WCTAssert(config != m_configs.end());
BasicConfig *basicConfig
= static_cast<BasicConfig *>(config->value().get());
basicConfig->setLiteModeEnable(m_liteModeEnable);
});
}
}
Expand Down Expand Up @@ -387,7 +382,7 @@ bool InnerDatabase::setupHandle(HandleType type, InnerHandle *handle)

handle->setTag(getTag());
handle->setType(type);
handle->setHasJournal(!m_liteModeEnable);
handle->setLiteModeEnable(m_liteModeEnable);
handle->setFullSQLTraceEnable(m_fullSQLTrace);
handle->setBusyTraceEnable(CommonCore::shared().isBusyTraceEnable());
HandleSlot slot = slotOfHandleType(type);
Expand Down
10 changes: 2 additions & 8 deletions src/common/core/config/BasicConfig.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -33,7 +33,6 @@ namespace WCDB {

BasicConfig::BasicConfig()
: Config()
, m_liteModeEnable(false)
, m_getJournalMode(StatementPragma().pragma(Pragma::journalMode()))
, m_enableCheckPointFullfsync(
StatementPragma().pragma(Pragma::checkpointFullfsync()).to(true))
Expand All @@ -56,7 +55,7 @@ bool BasicConfig::invoke(InnerHandle* handle)
if (!handle->isReadonly()) {
handle->setWALFilePersist(true);
succeed = lazySetJournalMode(handle);
if (!m_liteModeEnable) {
if (!handle->liteModeEnable()) {
succeed = succeed && handle->execute(m_enableCheckPointFullfsync);
} else {
succeed = succeed && handle->execute(m_disableFullSync);
Expand All @@ -68,11 +67,6 @@ bool BasicConfig::invoke(InnerHandle* handle)
return succeed;
}

void BasicConfig::setLiteModeEnable(bool enable)
{
m_liteModeEnable = enable;
}

#pragma mark - Journal Mode
bool BasicConfig::lazySetJournalMode(InnerHandle* handle)
{
Expand All @@ -85,7 +79,7 @@ bool BasicConfig::lazySetJournalMode(InnerHandle* handle)
continue;
}
succeed = true;
if (!m_liteModeEnable) {
if (!handle->liteModeEnable()) {
if (!journalMode.value().caseInsensitiveEqual("WAL")) {
if (!handle->canWriteMainDB()) {
succeed = false;
Expand Down
2 changes: 0 additions & 2 deletions src/common/core/config/BasicConfig.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -35,7 +35,6 @@ class BasicConfig final : public Config {
~BasicConfig() override;

bool invoke(InnerHandle* handle) override final;
void setLiteModeEnable(bool enable);

#pragma mark - Journal Mode
protected:
Expand All @@ -46,7 +45,6 @@ class BasicConfig final : public Config {
bool setJournalMode(InnerHandle* handle, const UnsafeStringView& mode);

private:
bool m_liteModeEnable = false;
const StatementPragma m_getJournalMode;

#pragma mark - FullFsync
Expand Down
13 changes: 9 additions & 4 deletions src/common/core/sqlite/AbstractHandle.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -37,7 +37,7 @@ AbstractHandle::AbstractHandle()
: m_handle(nullptr)
, m_customOpenFlag(0)
, m_tag(Tag::invalid())
, m_hasJournal(true)
, m_enableLiteMode(false)
, m_transactionLevel(0)
, m_transactionError(TransactionError::Allowed)
, m_cacheTransactionError(TransactionError::Allowed)
Expand Down Expand Up @@ -199,9 +199,14 @@ bool AbstractHandle::canWriteMainDB()
return m_customOpenFlag & SQLITE_OPEN_READWRITE;
}

void AbstractHandle::setHasJournal(bool hasJournal)
void AbstractHandle::setLiteModeEnable(bool enable)
{
m_hasJournal = hasJournal;
m_enableLiteMode = enable;
}

bool AbstractHandle::liteModeEnable() const
{
return m_enableLiteMode;
}

int AbstractHandle::getChanges()
Expand Down Expand Up @@ -573,7 +578,7 @@ bool AbstractHandle::commitTransaction()

void AbstractHandle::rollbackTransaction()
{
if (!m_hasJournal) {
if (m_enableLiteMode) {
notifyError(Error::Code::Misuse, "", "Can not execute rollback in a database without rollback journal.");
commitTransaction();
return;
Expand Down
5 changes: 3 additions & 2 deletions src/common/core/sqlite/AbstractHandle.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -77,7 +77,8 @@ class AbstractHandle : public ErrorProne {

void enableWriteMainDB(bool enable);
bool canWriteMainDB();
void setHasJournal(bool hasJournal);
void setLiteModeEnable(bool enable);
bool liteModeEnable() const;

long long getLastInsertedRowID();
// const char *getErrorMessage();
Expand All @@ -97,7 +98,7 @@ class AbstractHandle : public ErrorProne {
protected:
int m_customOpenFlag;
Tag m_tag;
bool m_hasJournal = true;
bool m_enableLiteMode = false;

#pragma mark - Statement
public:
Expand Down

0 comments on commit 88095f6

Please sign in to comment.