// ---------------------------------------------------------------------- // File: VersionedHashRevisionTracker.hh // Author: Georgios Bitzes - CERN // ---------------------------------------------------------------------- /************************************************************************ * quarkdb - a redis-like highly available key-value store * * Copyright (C) 2019 CERN/Switzerland * * * * This program is free software: you can redistribute it and/or modify * * it under the terms of the GNU General Public License as published by * * the Free Software Foundation, either version 3 of the License, or * * (at your option) any later version. * * * * This program is distributed in the hope that it will be useful, * * but WITHOUT ANY WARRANTY; without even the implied warranty of * * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the * * GNU General Public License for more details. * * * * You should have received a copy of the GNU General Public License * * along with this program. If not, see .* ************************************************************************/ #ifndef QUARKDB_VERSIONED_HASH_REVISION_TRACKER_HH #define QUARKDB_VERSIONED_HASH_REVISION_TRACKER_HH #include #include #include #include namespace quarkdb { //------------------------------------------------------------------------------ // Describes updates during a single revision for a specific versioned hash. //------------------------------------------------------------------------------ class VersionedHashRevision { public: //---------------------------------------------------------------------------- // Indicate which revision we're referring to. When called multiple times // for the same object, the given value MUST be the same. //---------------------------------------------------------------------------- void setRevisionNumber(uint64_t rev); //---------------------------------------------------------------------------- // Add to update batch - empty value indicates deletion //---------------------------------------------------------------------------- void addUpdate(std::string_view field, std::string_view value); //---------------------------------------------------------------------------- // Serialize contents //---------------------------------------------------------------------------- std::string serialize() const; private: uint64_t currentRevision = 0; std::vector> updateBatch; }; //------------------------------------------------------------------------------ // Tracks all revisions during a single transaction, which could affect // multiple keys. //------------------------------------------------------------------------------ class VersionedHashRevisionTracker { public: //---------------------------------------------------------------------------- // Get revision for a specific key //---------------------------------------------------------------------------- VersionedHashRevision& forKey(std::string_view key); //---------------------------------------------------------------------------- // Is it empty? //---------------------------------------------------------------------------- bool empty() const { return contents.empty(); } //---------------------------------------------------------------------------- // Iterate through contents //---------------------------------------------------------------------------- std::map::iterator begin(); std::map::iterator end(); private: std::map contents; }; } #endif