1 /***************************************************************************** 2 * $Id: bisi_record.hpp 612471 2020-07-22 15:04:49Z saprykin $ 3 * =========================================================================== 4 * 5 * PUBLIC DOMAIN NOTICE 6 * National Center for Biotechnology Information 7 * 8 * This software/database is a "United States Government Work" under the 9 * terms of the United States Copyright Act. It was written as part of 10 * the author's official duties as a United States Government employee and 11 * thus cannot be copyrighted. This software/database is freely available 12 * to the public for use. The National Library of Medicine and the U.S. 13 * Government have not placed any restriction on its use or reproduction. 14 * 15 * Although all reasonable efforts have been taken to ensure the accuracy 16 * and reliability of the software and data, the NLM and the U.S. 17 * Government do not and cannot warrant the performance or results that 18 * may be obtained by using this software or data. The NLM and the U.S. 19 * Government disclaim all warranties, express or implied, including 20 * warranties of performance, merchantability or fitness for any particular 21 * purpose. 22 * 23 * Please cite the author in any work or product based on this material. 24 * 25 * BiSi: changelog record 26 * 27 *****************************************************************************/ 28 29 #ifndef OBJTOOLS__PUBSEQ_GATEWAY__CASSANDRA__CHANGELOG__BISI_RECORD_HPP 30 #define OBJTOOLS__PUBSEQ_GATEWAY__CASSANDRA__CHANGELOG__BISI_RECORD_HPP 31 32 #include <corelib/ncbistd.hpp> 33 34 #include <chrono> 35 #include <string> 36 37 #include <objtools/pubseq_gateway/impl/cassandra/IdCassScope.hpp> 38 #include <objtools/pubseq_gateway/impl/cassandra/cass_util.hpp> 39 40 BEGIN_IDBLOB_SCOPE 41 USING_NCBI_SCOPE; 42 43 using TBiSiChangelogOperationBase = int8_t; 44 enum class TBiSiChangelogOperation : TBiSiChangelogOperationBase 45 { 46 eUndefined = 0, 47 eChangeLogOpInsert = 'I', 48 eChangeLogOpErase = 'E', 49 eChangeLogOpBeacon = 'U', 50 }; 51 52 class CBiSiPartitionMaker 53 { 54 static constexpr int64_t kChangelogGranularitySec = 120; 55 static constexpr int64_t kChangelogTtlSec = 14L * 24 * 3600; // 14 days 56 57 public: GetCurrentPartition() const58 int64_t GetCurrentPartition() const 59 { 60 CTime time; 61 time.SetCurrent(); 62 int64_t update_time = CTimeToTimeTms(time); 63 int64_t granularity_ms = kChangelogGranularitySec * 1000; 64 return (update_time / granularity_ms) * granularity_ms; 65 } 66 GetGranularitySec() const67 constexpr int64_t GetGranularitySec() const 68 { 69 return kChangelogGranularitySec; 70 } 71 GetTTLSec() const72 constexpr int64_t GetTTLSec() const 73 { 74 return kChangelogTtlSec; 75 } 76 }; 77 78 class CSiChangelogRecord 79 { 80 81 public: 82 CSiChangelogRecord(); CSiChangelogRecord(int64_t partition,string seq_id,int16_t seq_id_type,TBiSiChangelogOperation operation)83 CSiChangelogRecord(int64_t partition, string seq_id, int16_t seq_id_type, TBiSiChangelogOperation operation) 84 : m_Partition(partition) 85 , m_SeqId(seq_id) 86 , m_SeqIdType(seq_id_type) 87 , m_Operation(operation) 88 { 89 } 90 CSiChangelogRecord(CSiChangelogRecord const &) = default; 91 CSiChangelogRecord(CSiChangelogRecord &&) = default; 92 93 CSiChangelogRecord& operator=(CSiChangelogRecord const &) = default; 94 CSiChangelogRecord& operator=(CSiChangelogRecord&&) = default; 95 GetPartition() const96 int64_t GetPartition() const { 97 return m_Partition; 98 } GetSeqId() const99 string GetSeqId() const { 100 return m_SeqId; 101 } GetSeqIdType() const102 int16_t GetSeqIdType() const { 103 return m_SeqIdType; 104 } 105 GetOperation() const106 TBiSiChangelogOperation GetOperation() const { 107 return m_Operation; 108 } GetOperationBase() const109 TBiSiChangelogOperationBase GetOperationBase() const { 110 return static_cast<TBiSiChangelogOperationBase>(m_Operation); 111 } 112 113 private: 114 int64_t m_Partition; 115 string m_SeqId; 116 int16_t m_SeqIdType; 117 TBiSiChangelogOperation m_Operation; 118 }; 119 120 class CBiChangelogRecord 121 { 122 public: 123 CBiChangelogRecord(); CBiChangelogRecord(int64_t partition,string accession,int16_t version,int16_t seq_id_type,int64_t gi,TBiSiChangelogOperation operation)124 CBiChangelogRecord( 125 int64_t partition, string accession, int16_t version, int16_t seq_id_type, int64_t gi, TBiSiChangelogOperation operation 126 ) 127 : m_Partition(partition) 128 , m_Accession(accession) 129 , m_Gi(gi) 130 , m_Version(version) 131 , m_SeqIdType(seq_id_type) 132 , m_Operation(operation) 133 { 134 } 135 CBiChangelogRecord(CBiChangelogRecord const &) = default; 136 CBiChangelogRecord(CBiChangelogRecord &&) = default; 137 138 CBiChangelogRecord& operator=(CBiChangelogRecord const &) = default; 139 CBiChangelogRecord& operator=(CBiChangelogRecord&&) = default; 140 GetPartition() const141 int64_t GetPartition() const { 142 return m_Partition; 143 } GetAccession() const144 string GetAccession() const { 145 return m_Accession; 146 } GetGi() const147 int64_t GetGi() const { 148 return m_Gi; 149 } GetVersion() const150 int16_t GetVersion() const { 151 return m_Version; 152 } GetSeqIdType() const153 int16_t GetSeqIdType() const { 154 return m_SeqIdType; 155 } 156 GetOperation() const157 TBiSiChangelogOperation GetOperation() const { 158 return m_Operation; 159 } GetOperationBase() const160 TBiSiChangelogOperationBase GetOperationBase() const { 161 return static_cast<TBiSiChangelogOperationBase>(m_Operation); 162 } 163 164 private: 165 int64_t m_Partition; 166 string m_Accession; 167 int64_t m_Gi; 168 int16_t m_Version; 169 int16_t m_SeqIdType; 170 TBiSiChangelogOperation m_Operation; 171 }; 172 173 END_IDBLOB_SCOPE 174 175 #endif // OBJTOOLS__PUBSEQ_GATEWAY__CASSANDRA__CHANGELOG__BISI_RECORD_HPP 176