Add function to read pages from RawDiskQueue_TwoFiles

This commit is contained in:
Alex Miller 2019-02-07 17:02:15 -08:00
parent 601b229c05
commit 2570b37e6e
2 changed files with 19 additions and 0 deletions

View File

@ -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 ) {

View File

@ -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);