mirror of
https://github.com/apple/foundationdb.git
synced 2025-05-14 01:42:37 +08:00
Restore buffering logic lost to botched merge
This commit is contained in:
parent
dadc4d1b21
commit
5743fe724c
@ -31,15 +31,37 @@ namespace {
|
|||||||
class BackupFile : public IBackupFile, ReferenceCounted<BackupFile> {
|
class BackupFile : public IBackupFile, ReferenceCounted<BackupFile> {
|
||||||
public:
|
public:
|
||||||
BackupFile(std::string fileName, Reference<IAsyncFile> file, std::string finalFullPath)
|
BackupFile(std::string fileName, Reference<IAsyncFile> file, std::string finalFullPath)
|
||||||
: IBackupFile(fileName), m_file(file), m_finalFullPath(finalFullPath), m_offset(0) {}
|
: IBackupFile(fileName), m_file(file), m_finalFullPath(finalFullPath), m_writeOffset(0) {
|
||||||
|
m_buffer.reserve(m_buffer.arena(), CLIENT_KNOBS->BACKUP_LOCAL_FILE_WRITE_BLOCK);
|
||||||
|
}
|
||||||
|
|
||||||
Future<Void> append(const void* data, int len) {
|
Future<Void> append(const void* data, int len) {
|
||||||
Future<Void> r = m_file->write(data, len, m_offset);
|
m_buffer.append(m_buffer.arena(), (const uint8_t*)data, len);
|
||||||
m_offset += len;
|
|
||||||
|
if (m_buffer.size() >= CLIENT_KNOBS->BACKUP_LOCAL_FILE_WRITE_BLOCK) {
|
||||||
|
return flush(CLIENT_KNOBS->BACKUP_LOCAL_FILE_WRITE_BLOCK);
|
||||||
|
}
|
||||||
|
|
||||||
|
return Void();
|
||||||
|
}
|
||||||
|
|
||||||
|
Future<Void> flush(int size) {
|
||||||
|
ASSERT(size <= m_buffer.size());
|
||||||
|
|
||||||
|
// Keep a reference to the old buffer
|
||||||
|
Standalone<VectorRef<uint8_t>> old = m_buffer;
|
||||||
|
// Make a new buffer, initialized with the excess bytes over the block size from the old buffer
|
||||||
|
m_buffer = Standalone<VectorRef<uint8_t>>(old.slice(size, old.size()));
|
||||||
|
|
||||||
|
// Write the old buffer to the underlying file and update the write offset
|
||||||
|
Future<Void> r = holdWhile(old, m_file->write(old.begin(), size, m_writeOffset));
|
||||||
|
m_writeOffset += size;
|
||||||
|
|
||||||
return r;
|
return r;
|
||||||
}
|
}
|
||||||
|
|
||||||
ACTOR static Future<Void> finish_impl(Reference<BackupFile> f) {
|
ACTOR static Future<Void> finish_impl(Reference<BackupFile> f) {
|
||||||
|
wait(f->flush(f->m_buffer.size()));
|
||||||
wait(f->m_file->truncate(f->size())); // Some IAsyncFile implementations extend in whole block sizes.
|
wait(f->m_file->truncate(f->size())); // Some IAsyncFile implementations extend in whole block sizes.
|
||||||
wait(f->m_file->sync());
|
wait(f->m_file->sync());
|
||||||
std::string name = f->m_file->getFilename();
|
std::string name = f->m_file->getFilename();
|
||||||
@ -48,17 +70,18 @@ public:
|
|||||||
return Void();
|
return Void();
|
||||||
}
|
}
|
||||||
|
|
||||||
Future<Void> finish() { return finish_impl(Reference<BackupFile>::addRef(this)); }
|
int64_t size() const { return m_buffer.size() + m_writeOffset; }
|
||||||
|
|
||||||
int64_t size() const override { return m_offset; }
|
Future<Void> finish() { return finish_impl(Reference<BackupFile>::addRef(this)); }
|
||||||
|
|
||||||
void addref() override { return ReferenceCounted<BackupFile>::addref(); }
|
void addref() override { return ReferenceCounted<BackupFile>::addref(); }
|
||||||
void delref() override { return ReferenceCounted<BackupFile>::delref(); }
|
void delref() override { return ReferenceCounted<BackupFile>::delref(); }
|
||||||
|
|
||||||
private:
|
private:
|
||||||
Reference<IAsyncFile> m_file;
|
Reference<IAsyncFile> m_file;
|
||||||
|
Standalone<VectorRef<uint8_t>> m_buffer;
|
||||||
|
int64_t m_writeOffset;
|
||||||
std::string m_finalFullPath;
|
std::string m_finalFullPath;
|
||||||
int64_t m_offset;
|
|
||||||
};
|
};
|
||||||
|
|
||||||
ACTOR static Future<BackupContainerFileSystem::FilesAndSizesT> listFiles_impl(std::string path, std::string m_path) {
|
ACTOR static Future<BackupContainerFileSystem::FilesAndSizesT> listFiles_impl(std::string path, std::string m_path) {
|
||||||
|
Loading…
x
Reference in New Issue
Block a user