1 /* $Id: delete.cpp 611898 2020-07-13 14:20:05Z saprykin $
2 * ===========================================================================
3 *
4 * PUBLIC DOMAIN NOTICE
5 * National Center for Biotechnology Information
6 *
7 * This software/database is a "United States Government Work" under the
8 * terms of the United States Copyright Act. It was written as part of
9 * the author's official duties as a United States Government employee and
10 * thus cannot be copyrighted. This software/database is freely available
11 * to the public for use. The National Library of Medicine and the U.S.
12 * Government have not placed any restriction on its use or reproduction.
13 *
14 * Although all reasonable efforts have been taken to ensure the accuracy
15 * and reliability of the software and data, the NLM and the U.S.
16 * Government do not and cannot warrant the performance or results that
17 * may be obtained by using this software or data. The NLM and the U.S.
18 * Government disclaim all warranties, express or implied, including
19 * warranties of performance, merchantability or fitness for any particular
20 * purpose.
21 *
22 * Please cite the author in any work or product based on this material.
23 *
24 * ===========================================================================
25 *
26 * Authors: Dmitrii Saprykin
27 *
28 * File Description:
29 *
30 * Cassandra blob storage task to delete BioseqInfo record
31 *
32 */
33
34 #include <ncbi_pch.hpp>
35
36 #include <objtools/pubseq_gateway/impl/cassandra/bioseq_info_task/delete.hpp>
37 #include <objtools/pubseq_gateway/impl/cassandra/changelog/bisi_writer.hpp>
38
39 #include <memory>
40 #include <set>
41 #include <string>
42 #include <sstream>
43 #include <tuple>
44 #include <utility>
45 #include <vector>
46
47 #include <objtools/pubseq_gateway/impl/cassandra/cass_blob_op.hpp>
48 #include <objtools/pubseq_gateway/impl/cassandra/cass_driver.hpp>
49
50 BEGIN_IDBLOB_SCOPE
51
52
CCassBioseqInfoTaskDelete(unsigned int op_timeout_ms,shared_ptr<CCassConnection> connection,const string & keyspace,CBioseqInfoRecord::TAccession accession,CBioseqInfoRecord::TVersion version,CBioseqInfoRecord::TSeqIdType seq_id_type,CBioseqInfoRecord::TGI gi,unsigned int max_retries,TDataErrorCallback data_error_cb)53 CCassBioseqInfoTaskDelete::CCassBioseqInfoTaskDelete(
54 unsigned int op_timeout_ms,
55 shared_ptr<CCassConnection> connection,
56 const string & keyspace,
57 CBioseqInfoRecord::TAccession accession,
58 CBioseqInfoRecord::TVersion version,
59 CBioseqInfoRecord::TSeqIdType seq_id_type,
60 CBioseqInfoRecord::TGI gi,
61 unsigned int max_retries,
62 TDataErrorCallback data_error_cb
63 )
64 : CCassBlobWaiter(op_timeout_ms, connection, keyspace, 0, true, max_retries, move(data_error_cb))
65 , m_Accession(move(accession))
66 , m_Version(version)
67 , m_SeqIdType(seq_id_type)
68 , m_GI(gi)
69 {}
70
71
Wait1(void)72 void CCassBioseqInfoTaskDelete::Wait1(void)
73 {
74 bool restarted;
75 do {
76 restarted = false;
77 switch (m_State) {
78 case eError:
79 case eDone:
80 return;
81
82 case eInit: {
83 m_QueryArr.resize(1);
84 m_QueryArr[0].query = m_Conn->NewQuery();
85 m_QueryArr[0].restart_count = 0;
86 auto qry = m_QueryArr[0].query;
87 string sql = "DELETE FROM " + GetKeySpace() + ".bioseq_info WHERE accession = ? AND version = ? AND seq_it_type = ? AND gi = ?";
88 qry->NewBatch();
89
90 qry->SetSQL(sql, 4);
91 qry->BindStr(0, m_Accession);
92 qry->BindInt16(1, m_Version);
93 qry->BindInt16(2, m_SeqIdType);
94 qry->BindInt64(3, m_GI);
95 UpdateLastActivity();
96 qry->Execute(CASS_CONSISTENCY_LOCAL_QUORUM, m_Async);
97
98 int64_t partition = CBiSiPartitionMaker().GetCurrentPartition();
99 CBiChangelogRecord changelog_record(
100 partition, m_Accession, m_Version, m_SeqIdType, m_GI,
101 TBiSiChangelogOperation::eChangeLogOpErase
102 );
103 CBiSiChangelogWriter().WriteBiEvent(*qry, GetKeySpace(), changelog_record, CBiSiPartitionMaker().GetTTLSec());
104 CBiSiChangelogWriter().WriteBiPartition(*qry, GetKeySpace(), partition, CBiSiPartitionMaker().GetTTLSec());
105 SetupQueryCB3(qry);
106 qry->RunBatch();
107 m_State = eWaitingPropsDeleted;
108 break;
109 }
110
111 case eWaitingPropsDeleted: {
112 if (!CheckReady(m_QueryArr[0])) {
113 break;
114 }
115 CloseAll();
116 m_State = eDone;
117 break;
118 }
119
120 default: {
121 stringstream msg;
122 msg << "Failed to delete bioseq_info record (key=" << m_Keyspace << "." << m_Accession << "."
123 << m_Version << "." << m_SeqIdType << "." << m_GI << ") unexpected state (" << static_cast<int>(m_State) << ")";
124 Error(CRequestStatus::e502_BadGateway, CCassandraException::eQueryFailed, eDiag_Error, msg.str());
125 }
126 }
127 } while(restarted);
128 }
129
130 END_IDBLOB_SCOPE
131