mirror of
https://gitee.com/openharmony/distributeddatamgr_relational_store
synced 2024-11-23 07:00:41 +00:00
commit
25603a4ded
@ -62,7 +62,6 @@ private:
|
||||
static void DeleteCorruptedFlag(const std::string &dbPath);
|
||||
static std::string GetTimeWithMilliseconds(time_t sec, int64_t nsec);
|
||||
static std::string GetBundleName(const RdbCorruptedEvent &eventInfo);
|
||||
static bool HandTimeout(const std::string &dbPath);
|
||||
static Connection::Collector collector_;
|
||||
};
|
||||
} // namespace OHOS::NativeRdb
|
||||
|
@ -44,24 +44,17 @@ static constexpr int MAX_TIME_BUF_LEN = 32;
|
||||
static constexpr int MILLISECONDS_LEN = 3;
|
||||
static constexpr int NANO_TO_MILLI = 1000000;
|
||||
static constexpr int MILLI_PRE_SEC = 1000;
|
||||
static constexpr int TIME_OUT_MINUTES = 10;
|
||||
static std::unordered_map<std::string, std::chrono::steady_clock::time_point> dbfileLastTimeStatistical_;
|
||||
static std::mutex dbfilesMutex_;
|
||||
Connection::Collector RdbFaultHiViewReporter::collector_ = nullptr;
|
||||
|
||||
void RdbFaultHiViewReporter::ReportFault(const RdbCorruptedEvent &eventInfo)
|
||||
{
|
||||
RdbCorruptedEvent eventInfoAppend = eventInfo;
|
||||
if (HandTimeout(eventInfo.path)) {
|
||||
for (auto &[name, debugInfo] : eventInfo.debugInfos) {
|
||||
eventInfoAppend.appendix += "\n" + name + " :" + GetFileStatInfo(debugInfo);
|
||||
}
|
||||
LOG_WARN("database corrupted store:%{public}s, errCode:%{public}d, append:%{public}s",
|
||||
SqliteUtils::Anonymous(eventInfo.storeName).c_str(),
|
||||
eventInfo.errorCode,
|
||||
eventInfoAppend.appendix.c_str());
|
||||
}
|
||||
if (IsReportCorruptedFault(eventInfo.path)) {
|
||||
RdbCorruptedEvent eventInfoAppend = eventInfo;
|
||||
eventInfoAppend.appendix += Format(eventInfoAppend.debugInfos, "");
|
||||
LOG_WARN("corrupted %{public}s errCode:0x%{public}x [%{public}s]",
|
||||
SqliteUtils::Anonymous(eventInfoAppend.storeName).c_str(),
|
||||
eventInfoAppend.errorCode,
|
||||
eventInfoAppend.appendix.c_str());
|
||||
Report(eventInfoAppend);
|
||||
CreateCorruptedFlag(eventInfo.path);
|
||||
}
|
||||
@ -69,11 +62,12 @@ void RdbFaultHiViewReporter::ReportFault(const RdbCorruptedEvent &eventInfo)
|
||||
|
||||
void RdbFaultHiViewReporter::ReportRestore(const RdbCorruptedEvent &eventInfo)
|
||||
{
|
||||
RdbCorruptedEvent eventInfoAppend = eventInfo;
|
||||
for (auto &[name, debugInfo] : eventInfo.debugInfos) {
|
||||
eventInfoAppend.appendix += "\n" + name + " :" + GetFileStatInfo(debugInfo);
|
||||
if (IsReportCorruptedFault(eventInfo.path)) {
|
||||
return;
|
||||
}
|
||||
LOG_INFO("database restore store:%{public}s, errCode:%{public}d, append:%{public}s",
|
||||
RdbCorruptedEvent eventInfoAppend = eventInfo;
|
||||
eventInfoAppend.appendix += Format(eventInfoAppend.debugInfos, "");
|
||||
LOG_INFO("restored %{public}s errCode:0x%{public}x [%{public}s]",
|
||||
SqliteUtils::Anonymous(eventInfo.storeName).c_str(), eventInfo.errorCode, eventInfoAppend.appendix.c_str());
|
||||
Report(eventInfoAppend);
|
||||
DeleteCorruptedFlag(eventInfo.path);
|
||||
@ -173,22 +167,6 @@ std::string RdbFaultHiViewReporter::GetTimeWithMilliseconds(time_t sec, int64_t
|
||||
return oss.str();
|
||||
}
|
||||
|
||||
bool RdbFaultHiViewReporter::HandTimeout(const std::string &dbPath)
|
||||
{
|
||||
std::lock_guard<std::mutex> lock(dbfilesMutex_);
|
||||
auto now = std::chrono::steady_clock::now();
|
||||
if (dbfileLastTimeStatistical_.find(dbPath) != dbfileLastTimeStatistical_.end()) {
|
||||
auto lastTime = dbfileLastTimeStatistical_[dbPath];
|
||||
auto duration = std::chrono::duration_cast<std::chrono::minutes>(now - lastTime);
|
||||
if (duration.count() < TIME_OUT_MINUTES) {
|
||||
return false;
|
||||
}
|
||||
}
|
||||
LOG_DEBUG("dbPath %{public}s Last Time is update", SqliteUtils::Anonymous(dbPath).c_str());
|
||||
dbfileLastTimeStatistical_[dbPath] = now;
|
||||
return true;
|
||||
}
|
||||
|
||||
RdbCorruptedEvent RdbFaultHiViewReporter::Create(const RdbStoreConfig &config, int32_t errCode,
|
||||
const std::string &appendix)
|
||||
{
|
||||
|
@ -83,10 +83,6 @@ std::string RdbFaultHiViewReporter::GetBundleName(const RdbCorruptedEvent &event
|
||||
return "";
|
||||
}
|
||||
|
||||
bool RdbFaultHiViewReporter::HandTimeout(const std::string &dbPath)
|
||||
{
|
||||
return false;
|
||||
}
|
||||
std::string RdbFaultHiViewReporter::Format(const std::map<std::string, DebugInfo> &debugs, const std::string &header)
|
||||
{
|
||||
(void)debugs;
|
||||
|
@ -91,7 +91,7 @@ std::pair<RebuiltType, std::shared_ptr<ConnectionPool>> ConnPool::HandleDataCorr
|
||||
static_cast<uint32_t>(rebuiltType), SqliteUtils::Anonymous(storeConfig.GetName()).c_str(),
|
||||
storeConfig.IsEncrypt(), errCode, errno);
|
||||
} else {
|
||||
RdbFaultHiViewReporter::ReportRestore(RdbFaultHiViewReporter::Create(storeConfig, E_OK));
|
||||
Reportor::ReportRestore(Reportor::Create(storeConfig, E_OK, "RestoreType:Rebuild"));
|
||||
}
|
||||
|
||||
return result;
|
||||
|
@ -32,6 +32,7 @@
|
||||
namespace OHOS {
|
||||
namespace NativeRdb {
|
||||
using namespace OHOS::Rdb;
|
||||
using Reportor = RdbFaultHiViewReporter;
|
||||
RdStatement::RdStatement()
|
||||
{
|
||||
}
|
||||
@ -128,7 +129,7 @@ int RdStatement::Prepare(GRD_DB *db, const std::string &newSql)
|
||||
int ret = RdUtils::RdSqlPrepare(db, newSql.c_str(), newSql.length(), &tmpStmt, nullptr);
|
||||
if (ret != E_OK) {
|
||||
if (ret == E_SQLITE_CORRUPT && config_ != nullptr) {
|
||||
RdbFaultHiViewReporter::ReportFault(RdbFaultHiViewReporter::Create(*config_, ret));
|
||||
Reportor::ReportFault(Reportor::Create(*config_, ret));
|
||||
}
|
||||
if (tmpStmt != nullptr) {
|
||||
(void)RdUtils::RdSqlFinalize(tmpStmt);
|
||||
@ -296,7 +297,7 @@ int32_t RdStatement::Step()
|
||||
}
|
||||
int ret = RdUtils::RdSqlStep(stmtHandle_);
|
||||
if (ret == E_SQLITE_CORRUPT && config_ != nullptr) {
|
||||
RdbFaultHiViewReporter::ReportFault(RdbFaultHiViewReporter::Create(*config_, ret));
|
||||
Reportor::ReportFault(Reportor::Create(*config_, ret));
|
||||
}
|
||||
stepCnt_++;
|
||||
return ret;
|
||||
|
@ -17,6 +17,7 @@
|
||||
|
||||
#include "logger.h"
|
||||
#include "rdb_errno.h"
|
||||
#include "rdb_fault_hiview_reporter.h"
|
||||
#include "rdb_security_manager.h"
|
||||
#include "rdb_store_manager.h"
|
||||
#include "rdb_trace.h"
|
||||
@ -30,6 +31,7 @@
|
||||
namespace OHOS {
|
||||
namespace NativeRdb {
|
||||
using namespace OHOS::Rdb;
|
||||
using Reportor = RdbFaultHiViewReporter;
|
||||
|
||||
std::shared_ptr<RdbStore> RdbHelper::GetRdbStore(
|
||||
const RdbStoreConfig &config, int version, RdbOpenCallback &openCallback, int &errCode)
|
||||
@ -81,12 +83,13 @@ int RdbHelper::DeleteRdbStore(const std::string &dbFileName)
|
||||
LOG_ERROR("Store to delete doesn't exist, path %{public}s", SqliteUtils::Anonymous(dbFileName).c_str());
|
||||
return E_OK; // not not exist
|
||||
}
|
||||
RdbStoreConfig config(dbFileName);
|
||||
Reportor::ReportRestore(Reportor::Create(config, E_OK, "RestoreType:Restore"));
|
||||
|
||||
RdbStoreManager::GetInstance().Delete(dbFileName);
|
||||
RdbSecurityManager::GetInstance().DelAllKeyFiles(dbFileName);
|
||||
DeleteRdbStore(SqliteUtils::GetSlavePath(dbFileName));
|
||||
|
||||
RdbStoreConfig config(dbFileName);
|
||||
config.SetDBType(DB_SQLITE);
|
||||
int errCodeSqlite = Connection::Delete(config);
|
||||
|
||||
@ -110,6 +113,7 @@ int RdbHelper::DeleteRdbStore(const RdbStoreConfig &config)
|
||||
LOG_ERROR("not exist, path %{public}s", SqliteUtils::Anonymous(dbFile).c_str());
|
||||
return E_OK; // not not exist
|
||||
}
|
||||
Reportor::ReportRestore(Reportor::Create(config, E_OK, "RestoreType:Restore"));
|
||||
RdbStoreManager::GetInstance().Delete(dbFile);
|
||||
Connection::Delete(config);
|
||||
RdbSecurityManager::GetInstance().DelAllKeyFiles(dbFile);
|
||||
|
@ -69,6 +69,7 @@ using namespace OHOS::Rdb;
|
||||
using namespace std::chrono;
|
||||
using SqlStatistic = DistributedRdb::SqlStatistic;
|
||||
using RdbNotifyConfig = DistributedRdb::RdbNotifyConfig;
|
||||
using Reportor = RdbFaultHiViewReporter;
|
||||
#if !defined(WINDOWS_PLATFORM) && !defined(MAC_PLATFORM) && !defined(ANDROID_PLATFORM) && !defined(IOS_PLATFORM)
|
||||
using RdbMgr = DistributedRdb::RdbManagerImpl;
|
||||
#endif
|
||||
@ -1660,6 +1661,9 @@ int RdbStoreImpl::Commit()
|
||||
}
|
||||
auto [errCode, statement] = GetStatement(sqlStr);
|
||||
if (statement == nullptr) {
|
||||
if (errCode == E_DATABASE_BUSY || errCode == E_SQLITE_BUSY || E_SQLITE_LOCKED) {
|
||||
Reportor::Report(Reportor::Create(config_, E_DATABASE_BUSY, "ErrorType: Busy"));
|
||||
}
|
||||
LOG_ERROR("id: %{public}zu, storeName: %{public}s, statement error", transactionId,
|
||||
SqliteUtils::Anonymous(name_).c_str());
|
||||
return E_DATABASE_BUSY;
|
||||
@ -1889,7 +1893,7 @@ int RdbStoreImpl::Restore(const std::string &backupPath, const std::vector<uint8
|
||||
}
|
||||
#endif
|
||||
if (errCode == E_OK) {
|
||||
RdbFaultHiViewReporter::ReportRestore(RdbFaultHiViewReporter::Create(config_, E_OK));
|
||||
Reportor::ReportRestore(Reportor::Create(config_, E_OK));
|
||||
rebuild_ = RebuiltType::NONE;
|
||||
}
|
||||
if (!cloudTables_.empty()) {
|
||||
|
@ -40,8 +40,10 @@
|
||||
namespace OHOS {
|
||||
namespace NativeRdb {
|
||||
using namespace OHOS::Rdb;
|
||||
using Reportor = RdbFaultHiViewReporter;
|
||||
__attribute__((used))
|
||||
const bool RdbStoreManager::regCollector_ = RdbFaultHiViewReporter::RegCollector(RdbStoreManager::Collector);
|
||||
constexpr int RETRY_INTERVAL = 1;
|
||||
RdbStoreManager &RdbStoreManager::GetInstance()
|
||||
{
|
||||
static RdbStoreManager manager;
|
||||
@ -92,6 +94,12 @@ std::shared_ptr<RdbStore> RdbStoreManager::GetRdbStore(
|
||||
// TOD this lock should only work on storeCache_, add one more lock for connectionpool
|
||||
std::lock_guard<std::mutex> lock(mutex_);
|
||||
auto path = config.GetRoleType() == VISITOR ? config.GetVisitorDir() : config.GetPath();
|
||||
auto pool = TaskExecutor::GetInstance().GetExecutor();
|
||||
pool->Schedule(std::chrono::seconds(RETRY_INTERVAL), [path, config, this]() {
|
||||
if (IsConfigInvalidChanged(path, config)) {
|
||||
Reportor::Report(Reportor::Create(config, E_CONFIG_INVALID_CHANGE, "ErrorType:Encrypt diff"));
|
||||
}
|
||||
});
|
||||
std::shared_ptr<RdbStoreImpl> rdbStore = GetStoreFromCache(config, path);
|
||||
if (rdbStore != nullptr) {
|
||||
return rdbStore;
|
||||
|
@ -43,6 +43,7 @@ namespace NativeRdb {
|
||||
using namespace OHOS::Rdb;
|
||||
using namespace std::chrono;
|
||||
using SqlStatistic = DistributedRdb::SqlStatistic;
|
||||
using Reportor = RdbFaultHiViewReporter;
|
||||
// Setting Data Precision
|
||||
constexpr SqliteStatement::Action SqliteStatement::ACTIONS[ValueObject::TYPE_MAX];
|
||||
SqliteStatement::SqliteStatement() : readOnly_(false), columnCount_(0), numParameters_(0), stmt_(nullptr), sql_("")
|
||||
@ -78,7 +79,7 @@ int SqliteStatement::Prepare(sqlite3 *dbHandle, const std::string &newSql)
|
||||
int ret = SQLiteError::ErrNo(errCode);
|
||||
if (config_ != nullptr &&
|
||||
(errCode == SQLITE_CORRUPT || (errCode == SQLITE_NOTADB && config_->GetIter() != 0))) {
|
||||
RdbFaultHiViewReporter::ReportFault(RdbFaultHiViewReporter::Create(*config_, ret));
|
||||
Reportor::ReportFault(Reportor::Create(*config_, ret));
|
||||
}
|
||||
PrintInfoForDbError(ret, newSql);
|
||||
return ret;
|
||||
@ -288,7 +289,7 @@ int SqliteStatement::InnerStep()
|
||||
auto errCode = sqlite3_step(stmt_);
|
||||
int ret = SQLiteError::ErrNo(errCode);
|
||||
if (config_ != nullptr && (errCode == SQLITE_CORRUPT || (errCode == SQLITE_NOTADB && config_->GetIter() != 0))) {
|
||||
RdbFaultHiViewReporter::ReportFault(RdbFaultHiViewReporter::Create(*config_, ret));
|
||||
Reportor::ReportFault(Reportor::Create(*config_, ret));
|
||||
}
|
||||
PrintInfoForDbError(ret, sql_);
|
||||
return ret;
|
||||
|
Loading…
Reference in New Issue
Block a user