Add function to read pages from RawDiskQueue_TwoFiles
This commit is contained in:
parent
601b229c05
commit
2570b37e6e
|
@ -143,6 +143,8 @@ public:
|
|||
|
||||
Future<Void> setPoppedPage( int file, int64_t page, int64_t debugSeq ) { return setPoppedPage(this, file, page, debugSeq); }
|
||||
|
||||
// FIXME: let the caller pass in where to write the data.
|
||||
Future<Standalone<StringRef>> read(int file, int page, int nPages) { return read(this, file, page, nPages); }
|
||||
Future<Standalone<StringRef>> readNextPage() { return readNextPage(this); }
|
||||
Future<Void> truncateBeforeLastReadPage() { return truncateBeforeLastReadPage(this); }
|
||||
|
||||
|
@ -540,6 +542,15 @@ public:
|
|||
}
|
||||
}
|
||||
|
||||
ACTOR static Future<Standalone<StringRef>> read(RawDiskQueue_TwoFiles* self, int file, int pageOffset, int nPages) {
|
||||
state TrackMe trackMe(self);
|
||||
state const size_t bytesRequested = nPages * sizeof(Page);
|
||||
state Standalone<StringRef> result = makeAlignedString(sizeof(Page), bytesRequested);
|
||||
int bytesRead = wait( self->files[file].f->read( mutateString(result), bytesRequested, pageOffset*sizeof(Page) ) );
|
||||
ASSERT_WE_THINK(bytesRead == bytesRequested);
|
||||
return result;
|
||||
}
|
||||
|
||||
Future<int> fillReadingBuffer() {
|
||||
// If we're right at the end of a file...
|
||||
if ( readingPage*sizeof(Page) >= (size_t)files[readingFile].size ) {
|
||||
|
|
|
@ -547,6 +547,14 @@ inline static Standalone<StringRef> makeString( int length ) {
|
|||
return returnString;
|
||||
}
|
||||
|
||||
inline static Standalone<StringRef> makeAlignedString( int alignment, int length ) {
|
||||
Standalone<StringRef> returnString;
|
||||
uint8_t *outData = new (returnString.arena()) uint8_t[alignment + length];
|
||||
outData = (uint8_t*)((((uintptr_t)outData + (alignment - 1)) / alignment) * alignment);
|
||||
((StringRef&)returnString) = StringRef(outData, length);
|
||||
return returnString;
|
||||
}
|
||||
|
||||
inline static StringRef makeString( int length, Arena& arena ) {
|
||||
uint8_t *outData = new (arena) uint8_t[length];
|
||||
return StringRef(outData, length);
|
||||
|
|
Loading…
Reference in New Issue