proxygen
RecordIO.h
Go to the documentation of this file.
1 /*
2  * Copyright 2013-present Facebook, Inc.
3  *
4  * Licensed under the Apache License, Version 2.0 (the "License");
5  * you may not use this file except in compliance with the License.
6  * You may obtain a copy of the License at
7  *
8  * http://www.apache.org/licenses/LICENSE-2.0
9  *
10  * Unless required by applicable law or agreed to in writing, software
11  * distributed under the License is distributed on an "AS IS" BASIS,
12  * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13  * See the License for the specific language governing permissions and
14  * limitations under the License.
15  */
16 
26 #pragma once
27 #define FOLLY_IO_RECORDIO_H_
28 
29 #include <atomic>
30 #include <memory>
31 #include <mutex>
32 
33 #include <folly/File.h>
34 #include <folly/Range.h>
35 #include <folly/io/IOBuf.h>
37 
38 namespace folly {
39 
46  public:
60  explicit RecordIOWriter(File file, uint32_t fileId = 1);
61 
66  void write(std::unique_ptr<IOBuf> buf);
67 
72  off_t filePos() const {
73  return filePos_;
74  }
75 
76  private:
79  std::unique_lock<File> writeLock_;
80  std::atomic<off_t> filePos_;
81 };
82 
87  public:
88  class Iterator;
89 
96  typedef Iterator iterator;
98  typedef std::pair<ByteRange, off_t> value_type;
99  typedef value_type& reference;
100  typedef const value_type& const_reference;
101 
107  explicit RecordIOReader(File file, uint32_t fileId = 0);
108 
109  Iterator cbegin() const;
110  Iterator begin() const;
111  Iterator cend() const;
112  Iterator end() const;
113 
117  Iterator seek(off_t pos) const;
118 
119  private:
122 };
123 
124 namespace recordio_helpers {
125 
126 // We're exposing the guts of the RecordIO implementation for two reasons:
127 // 1. It makes unit testing easier, and
128 // 2. It allows you to build different RecordIO readers / writers that use
129 // different storage systems underneath (not standard files)
130 
134 constexpr size_t headerSize(); // defined in RecordIO-inl.h
135 
147 size_t prependHeader(std::unique_ptr<IOBuf>& buf, uint32_t fileId = 1);
148 
158 struct RecordInfo {
161 };
163 findRecord(ByteRange searchRange, ByteRange wholeRange, uint32_t fileId);
164 
169 
175 
176 } // namespace recordio_helpers
177 
178 } // namespace folly
179 
180 #include <folly/io/RecordIO-inl.h>
std::atomic< off_t > filePos_
Definition: RecordIO.h:80
std::unique_lock< File > writeLock_
Definition: RecordIO.h:79
constexpr size_t headerSize()
Definition: RecordIO-inl.h:101
size_t prependHeader(std::unique_ptr< IOBuf > &buf, uint32_t fileId)
Definition: RecordIO.cpp:139
Iterator const_iterator
Definition: RecordIO.h:97
off_t filePos() const
Definition: RecordIO.h:72
auto begin(TestAdlIterable &instance)
Definition: ForeachTest.cpp:56
—— Concurrent Priority Queue Implementation ——
Definition: AtomicBitSet.h:29
RecordInfo validateRecord(ByteRange range, uint32_t fileId)
Definition: RecordIO.cpp:170
auto end(TestAdlIterable &instance)
Definition: ForeachTest.cpp:62
constexpr Range< Iter > range(Iter first, Iter last)
Definition: Range.h:1114
value_type & reference
Definition: RecordIO.h:99
RecordIOWriter(File file, uint32_t fileId=1)
Definition: RecordIO.cpp:33
RecordInfo findRecord(ByteRange range, uint32_t fileId)
Definition: RecordIO-inl.h:105
MemoryMapping map_
Definition: RecordIO.h:120
void write(std::unique_ptr< IOBuf > buf)
Definition: RecordIO.cpp:48
const value_type & const_reference
Definition: RecordIO.h:100
std::pair< ByteRange, off_t > value_type
Definition: RecordIO.h:98
Iterator< typename Container::const_iterator > cbegin(const Container &c)
Definition: Padded.h:319
Iterator< typename Container::const_iterator > cend(const Container &c)
Definition: Padded.h:324