NCBI C++ ToolKit
chunk_file.hpp
Go to the documentation of this file.

Go to the SVN repository for this file.

1 #ifndef ASN_CACHE_CHUNK_FILE_HPP__
2 #define ASN_CACHE_CHUNK_FILE_HPP__
3 /* $Id: chunk_file.hpp 72616 2016-05-18 15:58:33Z gouriano $
4  * ===========================================================================
5  *
6  * PUBLIC DOMAIN NOTICE
7  * National Center for Biotechnology Information
8  *
9  * This software/database is a "United States Government Work" under the
10  * terms of the United States Copyright Act. It was written as part of
11  * the author's official duties as a United States Government employee and
12  * thus cannot be copyrighted. This software/database is freely available
13  * to the public for use. The National Library of Medicine and the U.S.
14  * Government have not placed any restriction on its use or reproduction.
15  *
16  * Although all reasonable efforts have been taken to ensure the accuracy
17  * and reliability of the software and data, the NLM and the U.S.
18  * Government do not and cannot warrant the performance or results that
19  * may be obtained by using this software or data. The NLM and the U.S.
20  * Government disclaim all warranties, express or implied, including
21  * warranties of performance, merchantability or fitness for any particular
22  * purpose.
23  *
24  * Please cite the author in any work or product based on this material.
25  *
26  * ===========================================================================
27  *
28  * Authors: Cheinan Marks
29  *
30  * File Description:
31  * Represent a chunk file -- a part of the ASN Cache ISAM storage model. The
32  * ISAM storage is broken into file-size chunks to prevent a block from
33  * getting too large. Chunks are serially numbered and cleverly named "chunk."
34  * The class keeps track of the currently used chunk and maintains a stream
35  * to it.
36  */
37 
38 #include <string>
39 #include <fstream>
40 
41 #include <corelib/ncbifile.hpp>
42 
43 #include <util/simple_buffer.hpp>
44 
45 #include <serial/objostrasnb.hpp>
46 
49 
51 using objects::CCache_blob;
52 
53 class CChunkFile : public CFile
54 {
55 public:
56  CChunkFile( const std::string &root_path = "", unsigned int chunk = 1)
57  : m_ChunkSerialNum(chunk)
58  , m_ChunkSize(-1)
59  , m_OpenFileRootPath(root_path)
61 
62  void OpenForWrite( const std::string & root_path = "");
63  void OpenForRead( const std::string & root_path = "",
64  unsigned int chunk = 0);
65  void Write( const CCache_blob & cache_blob );
66  void RawWrite( const char * raw_blob, size_t raw_blob_size );
67  void Read( CCache_blob & target, std::streampos offset, size_t blob_size );
68  void RawRead( std::streampos offset, char * raw_blob, size_t raw_blob_size );
69  size_t Append( const string & root_path,
70  const CFile & input_chunk_file,
71  Uint8 input_offset = 0 );
72  Int8 GetOffset() { return m_FileStream.tellp(); }
73  unsigned int GetChunkSerialNum() const { return m_ChunkSerialNum; }
74 
75  static std::string s_MakeChunkFileName( const std::string & root_path, unsigned int serial_num );
76  static unsigned int s_FindNextChunk( const std::string & root_path,
77  unsigned int serial_num,
78  Uint8 &size );
79  static unsigned int s_FindLastChunk( const std::string & root_path );
80 
81 private:
82  unsigned int m_ChunkSerialNum;
88 
89  void x_ReserveBufferSpace() { m_Buffer.reserve(128 * 1024); }
90 
91  static const Int8 m_kMaxChunkSize = 4 * 1024 * 1024 * 1024LL;
92 };
93 
95 #endif // ASN_CACHE_CHUNK_FILE_HPP__
96 
User-defined methods of the data storage class.
Int8 m_ChunkSize
Definition: chunk_file.hpp:83
size_t Append(const string &root_path, const CFile &input_chunk_file, Uint8 input_offset=0)
Definition: chunk_file.cpp:195
void Read(CCache_blob &target, std::streampos offset, size_t blob_size)
Definition: chunk_file.cpp:157
static std::string s_MakeChunkFileName(const std::string &root_path, unsigned int serial_num)
Definition: chunk_file.cpp:229
unsigned int m_ChunkSerialNum
Definition: chunk_file.hpp:82
static unsigned int s_FindNextChunk(const std::string &root_path, unsigned int serial_num, Uint8 &size)
Definition: chunk_file.cpp:238
Int8 GetOffset()
Definition: chunk_file.hpp:72
void x_ReserveBufferSpace()
Definition: chunk_file.hpp:89
std::string m_OpenFilePath
Definition: chunk_file.hpp:85
CNcbiFstream m_FileStream
Definition: chunk_file.hpp:84
void OpenForWrite(const std::string &root_path="")
Definition: chunk_file.cpp:54
void RawWrite(const char *raw_blob, size_t raw_blob_size)
Definition: chunk_file.cpp:150
CSimpleBufferT< char > m_Buffer
Definition: chunk_file.hpp:87
void Write(const CCache_blob &cache_blob)
Definition: chunk_file.cpp:141
unsigned int GetChunkSerialNum() const
Definition: chunk_file.hpp:73
void OpenForRead(const std::string &root_path="", unsigned int chunk=0)
Definition: chunk_file.cpp:99
CChunkFile(const std::string &root_path="", unsigned int chunk=1)
Definition: chunk_file.hpp:56
static const Int8 m_kMaxChunkSize
Definition: chunk_file.hpp:91
void RawRead(std::streampos offset, char *raw_blob, size_t raw_blob_size)
Definition: chunk_file.cpp:171
static unsigned int s_FindLastChunk(const std::string &root_path)
Definition: chunk_file.cpp:259
std::string m_OpenFileRootPath
Definition: chunk_file.hpp:86
CFile –.
Definition: ncbifile.hpp:1604
void reserve(size_type new_size)
string
Definition: cgiapp.hpp:687
int64_t Int8
8-byte (64-bit) signed integer
Definition: ncbitype.h:104
uint64_t Uint8
8-byte (64-bit) unsigned integer
Definition: ncbitype.h:105
#define END_NCBI_SCOPE
End previously defined NCBI scope.
Definition: ncbistl.hpp:103
#define BEGIN_NCBI_SCOPE
Define ncbi namespace.
Definition: ncbistl.hpp:100
IO_PREFIX::fstream CNcbiFstream
Portable alias for fstream.
Definition: ncbistre.hpp:538
const struct ncbi::grid::netcache::search::fields::SIZE size
Defines classes: CDirEntry, CFile, CDir, CSymLink, CMemoryFile, CFileUtil, CFileLock,...
int offset
Definition: replacements.h:160
Modified on Fri Feb 23 11:42:41 2024 by modify_doxy.py rev. 669887