1 #ifndef PSGS_CASSBLOBBASE__HPP
2 #define PSGS_CASSBLOBBASE__HPP
3 
4 /*  $Id: cass_blob_base.hpp 629837 2021-04-22 12:47:49Z ivanov $
5  * ===========================================================================
6  *
7  *                            PUBLIC DOMAIN NOTICE
8  *               National Center for Biotechnology Information
9  *
10  *  This software/database is a "United States Government Work" under the
11  *  terms of the United States Copyright Act.  It was written as part of
12  *  the author's official duties as a United States Government employee and
13  *  thus cannot be copyrighted.  This software/database is freely available
14  *  to the public for use. The National Library of Medicine and the U.S.
15  *  Government have not placed any restriction on its use or reproduction.
16  *
17  *  Although all reasonable efforts have been taken to ensure the accuracy
18  *  and reliability of the software and data, the NLM and the U.S.
19  *  Government do not and cannot warrant the performance or results that
20  *  may be obtained by using this software or data. The NLM and the U.S.
21  *  Government disclaim all warranties, express or implied, including
22  *  warranties of performance, merchantability or fitness for any particular
23  *  purpose.
24  *
25  *  Please cite the author in any work or product based on this material.
26  *
27  * ===========================================================================
28  *
29  * Authors: Sergey Satskiy
30  *
31  * File Description: base class for processors which retrieve blobs
32  *
33  */
34 
35 #include <corelib/request_status.hpp>
36 #include <corelib/ncbidiag.hpp>
37 
38 #include "cass_fetch.hpp"
39 #include "psgs_request.hpp"
40 #include "psgs_reply.hpp"
41 #include "cass_processor_base.hpp"
42 #include "get_blob_callback.hpp"
43 #include "id2info.hpp"
44 #include "cass_blob_id.hpp"
45 
46 USING_NCBI_SCOPE;
47 USING_IDBLOB_SCOPE;
48 
49 
50 class CPSGS_CassBlobBase : virtual public CPSGS_CassProcessorBase
51 {
52 public:
53     CPSGS_CassBlobBase();
54     CPSGS_CassBlobBase(shared_ptr<CPSGS_Request>  request,
55                        shared_ptr<CPSGS_Reply>  reply,
56                        const string &  processor_id);
57     virtual ~CPSGS_CassBlobBase();
58 
59 protected:
60     void OnGetBlobProp(TBlobPropsCB  blob_props_cb,
61                        TBlobChunkCB  blob_chunk_cb,
62                        TBlobErrorCB  blob_error_cb,
63                        CCassBlobFetch *  fetch_details,
64                        CBlobRecord const &  blob, bool is_found);
65     void OnGetBlobError(CCassBlobFetch *  fetch_details,
66                         CRequestStatus::ECode  status, int  code,
67                         EDiagSev  severity, const string &  message);
68     void OnGetBlobChunk(bool  cancelled,
69                         CCassBlobFetch *  fetch_details,
70                         const unsigned char *  chunk_data,
71                         unsigned int  data_size, int  chunk_no);
72     void SetFinished(CCassBlobFetch *  fetch_details);
73     bool CountError(CRequestStatus::ECode  status,
74                     int  code,
75                     EDiagSev  severity,
76                     const string &  message);
77     bool NeedToAddId2CunkId2Info(void) const;
78     void PrepareServerErrorMessage(CCassBlobFetch *  fetch_details,
79                                    int  code,
80                                    EDiagSev  severity,
81                                    const string &  message);
82     void OnPublicCommentError(CCassPublicCommentFetch *  fetch_details,
83                               CRequestStatus::ECode  status,
84                               int  code,
85                               EDiagSev  severity,
86                               const string &  message);
87     void OnPublicComment(CCassPublicCommentFetch *  fetch_details,
88                          string  comment,
89                          bool  is_found);
90 
91 private:
92     void x_OnBlobPropNoneTSE(CCassBlobFetch *  fetch_details);
93     void x_OnBlobPropSlimTSE(TBlobPropsCB  blob_props_cb,
94                              TBlobChunkCB  blob_chunk_cb,
95                              TBlobErrorCB  blob_error_cb,
96                              CCassBlobFetch *  fetch_details,
97                              CBlobRecord const &  blob);
98     void x_OnBlobPropSmartTSE(TBlobPropsCB  blob_props_cb,
99                               TBlobChunkCB  blob_chunk_cb,
100                               TBlobErrorCB  blob_error_cb,
101                               CCassBlobFetch *  fetch_details,
102                               CBlobRecord const &  blob);
103     void x_OnBlobPropWholeTSE(TBlobPropsCB  blob_props_cb,
104                               TBlobChunkCB  blob_chunk_cb,
105                               TBlobErrorCB  blob_error_cb,
106                               CCassBlobFetch *  fetch_details,
107                               CBlobRecord const &  blob);
108     void x_OnBlobPropOrigTSE(TBlobChunkCB  blob_chunk_cb,
109                              TBlobErrorCB  blob_error_cb,
110                              CCassBlobFetch *  fetch_details,
111                              CBlobRecord const &  blob);
112 
113 private:
114     void x_RequestOriginalBlobChunks(TBlobChunkCB  blob_chunk_cb,
115                                      TBlobErrorCB  blob_error_cb,
116                                      CCassBlobFetch *  fetch_details,
117                                      CBlobRecord const &  blob);
118     void x_RequestID2BlobChunks(TBlobPropsCB  blob_props_cb,
119                                 TBlobChunkCB  blob_chunk_cb,
120                                 TBlobErrorCB  blob_error_cb,
121                                 CCassBlobFetch *  fetch_details,
122                                 CBlobRecord const &  blob,
123                                 bool  info_blob_only);
124     void x_RequestId2SplitBlobs(TBlobPropsCB  blob_props_cb,
125                                 TBlobChunkCB  blob_chunk_cb,
126                                 TBlobErrorCB  blob_error_cb,
127                                 CCassBlobFetch *  fetch_details,
128                                 const string &  sat_name);
129 
130 
131 private:
132     enum EPSGS_BlobCacheCheckResult {
133         ePSGS_InCache,
134         ePSGS_NotInCache
135     };
136 
137     EPSGS_BlobCacheCheckResult
138     x_CheckExcludeBlobCache(CCassBlobFetch *  fetch_details,
139                             SPSGS_BlobRequestBase &  blob_request);
140     void x_OnBlobPropNotFound(CCassBlobFetch *  fetch_details);
141     bool x_ParseId2Info(CCassBlobFetch *  fetch_details,
142                         CBlobRecord const &  blob);
143     int64_t  x_GetId2ChunkNumber(CCassBlobFetch *  fetch_details);
144     void x_PrepareBlobPropData(CCassBlobFetch *  fetch_details,
145                                CBlobRecord const &  blob);
146     void x_PrepareBlobPropCompletion(CCassBlobFetch *  fetch_details);
147     void x_PrepareBlobData(CCassBlobFetch *  fetch_details,
148                            const unsigned char *  chunk_data,
149                            unsigned int  data_size,
150                            int  chunk_no);
151     void x_PrepareBlobCompletion(CCassBlobFetch *  fetch_details);
152     void x_PrepareBlobPropMessage(CCassBlobFetch *  fetch_details,
153                                   const string &  message,
154                                   CRequestStatus::ECode  status,
155                                   int  err_code,
156                                   EDiagSev  severity);
157     void x_PrepareBlobMessage(CCassBlobFetch *  fetch_details,
158                               const string &  message,
159                               CRequestStatus::ECode  status,
160                               int  err_code,
161                               EDiagSev  severity);
162     void x_PrepareBlobExcluded(CCassBlobFetch *  fetch_details,
163                                const string &  blob_id,
164                                EPSGS_BlobSkipReason  skip_reason);
165 
166 protected:
167     // Used for get blob by sat/sat key request
168     SCass_BlobId                                        m_BlobId;
169 
170 private:
171     bool                                                m_NeedToParseId2Info;
172     unique_ptr<CPSGS_SatInfoChunksVerFlavorId2Info>     m_Id2Info;
173     string                                              m_ProcessorId;
174 
175     // last_modified from the original blob props
176     CBlobRecord::TTimestamp                             m_LastModified;
177 };
178 
179 #endif  // PSGS_CASSBLOBBASE__HPP
180 
181