nsresult DOMStorageCache::RemoveItem(const DOMStorage* aStorage, const nsAString& aKey, nsString& aOld) { Telemetry::AutoTimer<Telemetry::LOCALDOMSTORAGE_REMOVEKEY_MS> autoTimer; if (Persist(aStorage)) { WaitForPreload(Telemetry::LOCALDOMSTORAGE_REMOVEKEY_BLOCKING_MS); if (NS_FAILED(mLoadResult)) { return mLoadResult; } } Data& data = DataSet(aStorage); if (!data.mKeys.Get(aKey, &aOld)) { SetDOMStringToNull(aOld); return NS_SUCCESS_DOM_NO_OPERATION; } // Recalculate the cached data size const int64_t delta = -(static_cast<int64_t>(aOld.Length())); unused << ProcessUsageDelta(aStorage, delta); data.mKeys.Remove(aKey); if (Persist(aStorage)) { return sDatabase->AsyncRemoveItem(this, aKey); } return NS_OK; }
nsresult DOMStorageCache::Clear(const DOMStorage* aStorage) { Telemetry::AutoTimer<Telemetry::LOCALDOMSTORAGE_CLEAR_MS> autoTimer; bool refresh = false; if (Persist(aStorage)) { // We need to preload all data (know the size) before we can proceeed // to correctly decrease cached usage number. // XXX as in case of unload, this is not technically needed now, but // after super-scope quota introduction we have to do this. Get telemetry // right now. WaitForPreload(Telemetry::LOCALDOMSTORAGE_CLEAR_BLOCKING_MS); if (NS_FAILED(mLoadResult)) { // When we failed to load data from the database, force delete of the // scope data and make use of the storage possible again. refresh = true; mLoadResult = NS_OK; } } Data& data = DataSet(aStorage); bool hadData = !!data.mKeys.Count(); if (hadData) { unused << ProcessUsageDelta(aStorage, -data.mOriginQuotaUsage); data.mKeys.Clear(); } if (Persist(aStorage) && (refresh || hadData)) { return sDatabase->AsyncClear(this); } return hadData ? NS_OK : NS_SUCCESS_DOM_NO_OPERATION; }
nsresult DOMStorageCache::RemoveItem(const DOMStorage* aStorage, const nsAString& aKey, nsString& aOld) { if (Persist(aStorage)) { WaitForPreload(Telemetry::LOCALDOMSTORAGE_REMOVEKEY_BLOCKING_MS); if (NS_FAILED(mLoadResult)) { return mLoadResult; } } Data& data = DataSet(aStorage); if (!data.mKeys.Get(aKey, &aOld)) { SetDOMStringToNull(aOld); return NS_SUCCESS_DOM_NO_OPERATION; } // Recalculate the cached data size const int64_t delta = -(static_cast<int64_t>(aOld.Length()) + static_cast<int64_t>(aKey.Length())); Unused << ProcessUsageDelta(aStorage, delta); data.mKeys.Remove(aKey); if (Persist(aStorage)) { if (!sDatabase) { NS_ERROR("Writing to localStorage after the database has been shut down" ", data lose!"); return NS_ERROR_NOT_INITIALIZED; } return sDatabase->AsyncRemoveItem(this, aKey); } return NS_OK; }
nsresult LocalStorageCache::SetItem(const LocalStorage* aStorage, const nsAString& aKey, const nsString& aValue, nsString& aOld, const MutationSource aSource) { // Size of the cache that will change after this action. int64_t delta = 0; if (Persist(aStorage)) { WaitForPreload(Telemetry::LOCALDOMSTORAGE_SETVALUE_BLOCKING_MS); if (NS_FAILED(mLoadResult)) { return mLoadResult; } } Data& data = DataSet(aStorage); if (!data.mKeys.Get(aKey, &aOld)) { SetDOMStringToNull(aOld); // We only consider key size if the key doesn't exist before. delta += static_cast<int64_t>(aKey.Length()); } delta += static_cast<int64_t>(aValue.Length()) - static_cast<int64_t>(aOld.Length()); if (!ProcessUsageDelta(aStorage, delta, aSource)) { return NS_ERROR_DOM_QUOTA_REACHED; } if (aValue == aOld && DOMStringIsNull(aValue) == DOMStringIsNull(aOld)) { return NS_SUCCESS_DOM_NO_OPERATION; } data.mKeys.Put(aKey, aValue); if (aSource == ContentMutation && Persist(aStorage)) { if (!sDatabase) { NS_ERROR("Writing to localStorage after the database has been shut down" ", data lose!"); return NS_ERROR_NOT_INITIALIZED; } if (DOMStringIsNull(aOld)) { return sDatabase->AsyncAddItem(this, aKey, aValue); } return sDatabase->AsyncUpdateItem(this, aKey, aValue); } return NS_OK; }
bool CPVRChannelGroupInternal::RemoveFromGroup(CPVRChannel *channel) { if (!channel) return false; CSingleLock lock(m_critSection); /* check if this channel is currently playing if we are hiding it */ CPVRChannel currentChannel; if (g_PVRManager.GetCurrentChannel(¤tChannel) && currentChannel == *channel) { CGUIDialogOK::ShowAndGetInput(19098,19101,0,19102); return false; } /* get the actual channel since this is called from a fileitemlist copy */ CPVRChannel *realChannel = (CPVRChannel *) GetByChannelID(channel->ChannelID()); if (!realChannel) return false; /* switch the hidden flag */ realChannel->SetHidden(true, true); ++m_iHiddenChannels; /* renumber this list */ Renumber(); /* and persist */ return Persist(); }
/** (Re)initialize for on-demand loading * * Calling Rollback will cancel all uncommitted changes. */ bool c4_Storage::Rollback(bool full_) { c4_Persist *pers = Persist(); bool f = Strategy().IsValid() && pers->Rollback(full_); // adjust our copy when the root view has been replaced *(c4_View*)this = &pers->Root(); return f; }
/// Define the storage to use for differential commits bool c4_Storage::SetAside(c4_Storage &aside_) { c4_Persist *pers = Persist(); bool f = pers->SetAside(aside_); // adjust our copy when the root view has been replaced *(c4_View*)this = &pers->Root(); return f; }
nsresult DOMStorageCache::GetKey(const DOMStorage* aStorage, uint32_t aIndex, nsAString& aRetval) { // XXX: This does a linear search for the key at index, which would // suck if there's a large numer of indexes. Do we care? If so, // maybe we need to have a lazily populated key array here or // something? if (Persist(aStorage)) { WaitForPreload(Telemetry::LOCALDOMSTORAGE_GETKEY_BLOCKING_MS); if (NS_FAILED(mLoadResult)) { return mLoadResult; } } aRetval.SetIsVoid(true); for (auto iter = DataSet(aStorage).mKeys.Iter(); !iter.Done(); iter.Next()) { if (aIndex == 0) { aRetval = iter.Key(); break; } aIndex--; } return NS_OK; }
/** * Save size (& optionally position) in registry */ void CMoveConstraint::LoadPosition(LPCTSTR szValueName, bool position) { m_sRegistryValueName = szValueName; m_bPersistent=true; Persist(false, position); }
c4_Storage::c4_Storage(const char *fname_, int mode_) { c4_FileStrategy *strat = d4_new c4_FileStrategy; strat->DataOpen(fname_, mode_); Initialize(*strat, true, mode_); if (strat->IsValid()) Persist()->LoadAll(); }
void SimpleCheckpoint::DoCheckpoint() { // TODO split checkpoint file into multiple files in the future // Create a new file for checkpoint CreateFile(); auto &log_manager = LogManager::GetInstance(); if (logger_ == nullptr) { logger_.reset(BackendLogger::GetBackendLogger(LOGGING_TYPE_NVM_WAL)); } start_commit_id_ = log_manager.GetGlobalMaxFlushedCommitId(); if (start_commit_id_ == INVALID_CID) { auto &txn_manager = concurrency::TransactionManagerFactory::GetInstance(); start_commit_id_ = txn_manager.GetMaxCommittedCid(); } LOG_TRACE("DoCheckpoint cid = %lu", start_commit_id_); // Add txn begin record std::shared_ptr<LogRecord> begin_record(new TransactionRecord( LOGRECORD_TYPE_TRANSACTION_BEGIN, start_commit_id_)); CopySerializeOutput begin_output_buffer; begin_record->Serialize(begin_output_buffer); records_.push_back(begin_record); auto &catalog_manager = catalog::Manager::GetInstance(); auto database_count = catalog_manager.GetDatabaseCount(); // loop all databases for (oid_t database_idx = 0; database_idx < database_count; database_idx++) { auto database = catalog_manager.GetDatabase(database_idx); auto table_count = database->GetTableCount(); auto database_oid = database->GetOid(); // loop all tables for (oid_t table_idx = 0; table_idx < table_count; table_idx++) { // Get the target table storage::DataTable *target_table = database->GetTable(table_idx); PL_ASSERT(target_table); LOG_TRACE("SeqScan: database idx %u table idx %u: %s", database_idx, table_idx, target_table->GetName().c_str()); Scan(target_table, database_oid); } } // Add txn commit record std::shared_ptr<LogRecord> commit_record(new TransactionRecord( LOGRECORD_TYPE_TRANSACTION_COMMIT, start_commit_id_)); CopySerializeOutput commit_output_buffer; commit_record->Serialize(commit_output_buffer); records_.push_back(commit_record); // TODO Add delimiter record for checkpoint recovery as well Persist(); Cleanup(); most_recent_checkpoint_cid = start_commit_id_; }
nsresult DOMStorageCache::SetItem(const DOMStorage* aStorage, const nsAString& aKey, const nsString& aValue, nsString& aOld) { if (Persist(aStorage)) { WaitForPreload(Telemetry::LOCALDOMSTORAGE_SETVALUE_BLOCKING_MS); if (NS_FAILED(mLoadResult)) { return mLoadResult; } } Data& data = DataSet(aStorage); if (!data.mKeys.Get(aKey, &aOld)) { SetDOMStringToNull(aOld); } // Check the quota first const int64_t delta = static_cast<int64_t>(aValue.Length()) - static_cast<int64_t>(aOld.Length()); if (!ProcessUsageDelta(aStorage, delta)) { return NS_ERROR_DOM_QUOTA_REACHED; } if (aValue == aOld && DOMStringIsNull(aValue) == DOMStringIsNull(aOld)) { return NS_SUCCESS_DOM_NO_OPERATION; } data.mKeys.Put(aKey, aValue); if (Persist(aStorage)) { if (!sDatabase) { NS_ERROR("Writing to localStorage after the database has been shut down" ", data lose!"); return NS_ERROR_NOT_INITIALIZED; } if (DOMStringIsNull(aOld)) { return sDatabase->AsyncAddItem(this, aKey, aValue); } return sDatabase->AsyncUpdateItem(this, aKey, aValue); } return NS_OK; }
bool CFavouritesService::Save(const CFileItemList& items) { { CSingleLock lock(m_criticalSection); m_favourites.Clear(); m_favourites.Copy(items); Persist(); } OnUpdated(); return true; }
bool CPVREpg::Update(const CEpg &epg, bool bUpdateDb /* = false */) { bool bReturn = CEpg::Update(epg, false); // don't update the db yet m_Channel = epg.m_Channel; m_bHasChannel = true; if (bUpdateDb) bReturn = Persist(false); return bReturn; }
void CMoveConstraint::OnDestroy() { if (m_bPersistent) Persist(true, true); UnSubclassWnd(); // the one variable that CANNOT safely be cleared now is m_bSubclassed // because the subclass is almost certainly not yet removed // (the subclass calls us to let us do destroy processing, before // removing itself) ClearMostData(); }
bool CEpg::Update(const CEpg &epg, bool bUpdateDb /* = false */) { bool bReturn = true; m_strName = epg.m_strName; m_strScraperName = epg.m_strScraperName; if (bUpdateDb) bReturn = Persist(false); return bReturn; }
nsresult LocalStorageCache::Clear(const LocalStorage* aStorage, const MutationSource aSource) { bool refresh = false; if (Persist(aStorage)) { // We need to preload all data (know the size) before we can proceeed // to correctly decrease cached usage number. // XXX as in case of unload, this is not technically needed now, but // after super-scope quota introduction we have to do this. Get telemetry // right now. WaitForPreload(Telemetry::LOCALDOMSTORAGE_CLEAR_BLOCKING_MS); if (NS_FAILED(mLoadResult)) { // When we failed to load data from the database, force delete of the // scope data and make use of the storage possible again. refresh = true; mLoadResult = NS_OK; } } Data& data = DataSet(aStorage); bool hadData = !!data.mKeys.Count(); if (hadData) { Unused << ProcessUsageDelta(aStorage, -data.mOriginQuotaUsage, aSource); data.mKeys.Clear(); } if (aSource == ContentMutation && Persist(aStorage) && (refresh || hadData)) { if (!sDatabase) { NS_ERROR("Writing to localStorage after the database has been shut down" ", data lose!"); return NS_ERROR_NOT_INITIALIZED; } return sDatabase->AsyncClear(this); } return hadData ? NS_OK : NS_SUCCESS_DOM_NO_OPERATION; }
HRESULT CACTController::PersistBank(IStream* pStm, bool bSave, int iBank) { // Rotaries binding if (FAILED(Persist(pStm, bSave, &m_dwKnobsBinding[iBank], sizeof(m_dwKnobsBinding[iBank])))) return E_FAIL; // Exclude rotaries from ACT if (FAILED(Persist(pStm, bSave, &m_bExcludeRotariesACT[iBank], sizeof(m_bExcludeRotariesACT[iBank])))) return E_FAIL; // Sliders binding if (FAILED(Persist(pStm, bSave, &m_dwSlidersBinding[iBank], sizeof(m_dwSlidersBinding[iBank])))) return E_FAIL; // Exclude sliders from ACT if (FAILED(Persist(pStm, bSave, &m_bExcludeSlidersACT[iBank], sizeof(m_bExcludeSlidersACT[iBank])))) return E_FAIL; // Buttons for (int n = 0; n < NUM_VIRTUAL_BUTTONS; n++) { if (FAILED(Persist(pStm, bSave, &m_dwButtonAction[iBank][n], sizeof(m_dwButtonAction[iBank][n])))) return E_FAIL; if (FAILED(Persist(pStm, bSave, &m_bButtonExcludeACT[iBank][n], sizeof(m_bButtonExcludeACT[iBank][n])))) return E_FAIL; } return S_OK; }
void DOMStorageCache::GetKeys(const DOMStorage* aStorage, nsTArray<nsString>& aKeys) { if (Persist(aStorage)) { WaitForPreload(Telemetry::LOCALDOMSTORAGE_GETALLKEYS_BLOCKING_MS); } if (NS_FAILED(mLoadResult)) { return; } DataSet(aStorage).mKeys.EnumerateRead(KeysArrayBuilder, &aKeys); }
nsresult DOMStorageCache::GetLength(const DOMStorage* aStorage, uint32_t* aRetval) { if (Persist(aStorage)) { WaitForPreload(Telemetry::LOCALDOMSTORAGE_GETLENGTH_BLOCKING_MS); if (NS_FAILED(mLoadResult)) { return mLoadResult; } } *aRetval = DataSet(aStorage).mKeys.Count(); return NS_OK; }
/// Define the complete view structure of the storage void c4_Storage::SetStructure(const char *description_) { d4_assert(description_ != 0); if (description_ != Description()) { c4_String s = "[" + c4_String(description_) + "]"; description_ = s; c4_Field *field = d4_new c4_Field(description_); d4_assert(! *description_); d4_assert(field != 0); Persist()->Root().Restructure(*field, false); } }
void DOMStorageCache::GetKeys(const DOMStorage* aStorage, nsTArray<nsString>& aKeys) { if (Persist(aStorage)) { WaitForPreload(Telemetry::LOCALDOMSTORAGE_GETALLKEYS_BLOCKING_MS); } if (NS_FAILED(mLoadResult)) { return; } for (auto iter = DataSet(aStorage).mKeys.Iter(); !iter.Done(); iter.Next()) { aKeys.AppendElement(iter.Key()); } }
HRESULT CACTController::Persist(IStream* pStm, bool bSave, CString *pStr) { int iLen; if (bSave) { iLen = pStr->GetLength(); if (FAILED(Persist(pStm, bSave, &iLen, sizeof(iLen)))) return E_FAIL; if (FAILED(Persist(pStm, bSave, (void *)(LPCTSTR)(*pStr), iLen))) return E_FAIL; } else { if (FAILED(Persist(pStm, bSave, &iLen, sizeof(iLen)))) return E_FAIL; HRESULT hr = Persist(pStm, bSave, pStr->GetBuffer(iLen), iLen); pStr->ReleaseBuffer(iLen); if (FAILED(hr)) return E_FAIL; } return S_OK; }
nsTArray<nsString>* DOMStorageCache::GetKeys(const DOMStorage* aStorage) { Telemetry::AutoTimer<Telemetry::LOCALDOMSTORAGE_GETALLKEYS_MS> autoTimer; if (Persist(aStorage)) { WaitForPreload(Telemetry::LOCALDOMSTORAGE_GETALLKEYS_BLOCKING_MS); } nsTArray<nsString>* result = new nsTArray<nsString>(); if (NS_SUCCEEDED(mLoadResult)) { DataSet(aStorage).mKeys.EnumerateRead(KeysArrayBuilder, result); } return result; }
Service& Service::operator=(const Service& s) { *reinterpret_cast<Persist *>(this) = Persist(s); service_label = s.service_label; service_descriptor = s.service_descriptor; service_identifier = s.service_identifier; country = s.country; language = s.language; language_long = s.language_long; audio_ref = s.audio_ref; data_ref = s.data_ref; afs_ref = s.afs_ref; conditional_access = s.conditional_access; ca_system_identifier = s.ca_system_identifier; ca_data = s.ca_data; announcement = s.announcement; return *this; }
nsresult DOMStorageCache::GetKey(const DOMStorage* aStorage, uint32_t aIndex, nsAString& aRetval) { // XXX: This does a linear search for the key at index, which would // suck if there's a large numer of indexes. Do we care? If so, // maybe we need to have a lazily populated key array here or // something? if (Persist(aStorage)) { WaitForPreload(Telemetry::LOCALDOMSTORAGE_GETKEY_BLOCKING_MS); if (NS_FAILED(mLoadResult)) { return mLoadResult; } } IndexFinderData data(aIndex, aRetval); DataSet(aStorage).mKeys.EnumerateRead(FindKeyOrder, &data); return NS_OK; }
bool ReplBacklog::Load(const std::string& path, uint32 backlog_size) { if (0 != m_backlog.Init(path, REPL_STATE_MAX_SIZE + backlog_size)) { return false; } m_state = (ReplPersistState*) (m_backlog.m_buf); m_state->repl_backlog_size = backlog_size; m_repl_backlog = (m_backlog.m_buf + REPL_STATE_MAX_SIZE); if (m_state->serverkey[0]) { /* * Loaded previous state, do nothing */ } else { std::string randomkey = random_hex_string(SERVER_KEY_SIZE); memcpy(m_state->serverkey, randomkey.data(), SERVER_KEY_SIZE); m_state->serverkey[SERVER_KEY_SIZE] = 0; m_state->repl_backlog_histlen = 0; m_state->repl_backlog_idx = 0; /* When a new backlog buffer is created, we increment the replication * offset by one to make sure we'll not be able to PSYNC with any * previous slave. This is needed because we avoid incrementing the * master_repl_offset if no backlog exists nor slaves are attached. */ m_state->master_repl_offset++; /* We don't have any data inside our buffer, but virtually the first * byte we have is the next byte that will be generated for the * replication stream. */ m_state->repl_backlog_off = m_state->master_repl_offset + 1; m_state->cksm = 0; m_state->current_db = ARDB_GLOBAL_DB; m_sync_state_change = true; Persist(); } m_last_sync_offset = m_state->repl_backlog_off; return true; }
nsresult DOMStorageCache::GetItem(const DOMStorage* aStorage, const nsAString& aKey, nsAString& aRetval) { if (Persist(aStorage)) { WaitForPreload(Telemetry::LOCALDOMSTORAGE_GETVALUE_BLOCKING_MS); if (NS_FAILED(mLoadResult)) { return mLoadResult; } } // not using AutoString since we don't want to copy buffer to result nsString value; if (!DataSet(aStorage).mKeys.Get(aKey, &value)) { SetDOMStringToNull(value); } aRetval = value; return NS_OK; }
bool CPVRChannelGroup::SetGroupName(const CStdString &strGroupName, bool bSaveInDb /* = false */) { bool bReturn(false); CSingleLock lock(m_critSection); if (m_strGroupName != strGroupName) { /* update the name */ m_strGroupName = strGroupName; m_bChanged = true; // SetChanged(); /* persist the changes */ if (bSaveInDb) Persist(); bReturn = true; } return bReturn; }
bool CPVRChannelGroup::MoveChannel(unsigned int iOldChannelNumber, unsigned int iNewChannelNumber, bool bSaveInDb /* = true */) { if (iOldChannelNumber == iNewChannelNumber) return true; bool bReturn(false); CSingleLock lock(m_critSection); /* make sure the list is sorted by channel number */ SortByChannelNumber(); /* old channel number out of range */ if (iOldChannelNumber > size()) return bReturn; /* new channel number out of range */ if (iNewChannelNumber > size()) iNewChannelNumber = size(); /* move the channel in the list */ PVRChannelGroupMember entry = at(iOldChannelNumber - 1); erase(begin() + iOldChannelNumber - 1); insert(begin() + iNewChannelNumber - 1, entry); /* renumber the list */ Renumber(); m_bChanged = true; if (bSaveInDb) bReturn = Persist(); else bReturn = true; CLog::Log(LOGNOTICE, "CPVRChannelGroup - %s - %s channel '%s' moved to channel number '%d'", __FUNCTION__, (m_bRadio ? "radio" : "tv"), entry.channel->ChannelName().c_str(), iNewChannelNumber); return true; }