2014-12-09 17:19:59 +01:00
|
|
|
#pragma once
|
|
|
|
#ifndef BLOCKSTORE_IMPLEMENTATIONS_ONDISK_ONDISKBLOCK_H_
|
|
|
|
#define BLOCKSTORE_IMPLEMENTATIONS_ONDISK_ONDISKBLOCK_H_
|
|
|
|
|
|
|
|
#include <boost/filesystem/path.hpp>
|
2015-03-12 14:27:51 +01:00
|
|
|
#include "../../interface/Block.h"
|
|
|
|
#include "../../utils/Data.h"
|
2014-12-09 17:19:59 +01:00
|
|
|
#include <iostream>
|
|
|
|
|
2015-02-17 00:23:33 +01:00
|
|
|
#include "messmer/cpp-utils/macros.h"
|
2014-12-09 17:19:59 +01:00
|
|
|
|
|
|
|
namespace blockstore {
|
|
|
|
namespace ondisk {
|
|
|
|
class OnDiskBlockStore;
|
|
|
|
|
|
|
|
class OnDiskBlock: public Block {
|
|
|
|
public:
|
|
|
|
virtual ~OnDiskBlock();
|
|
|
|
|
2015-01-24 22:08:41 +01:00
|
|
|
static std::unique_ptr<OnDiskBlock> LoadFromDisk(const boost::filesystem::path &rootdir, const Key &key);
|
2015-04-18 14:47:12 +02:00
|
|
|
static std::unique_ptr<OnDiskBlock> CreateOnDisk(const boost::filesystem::path &rootdir, const Key &key, Data data);
|
2015-02-22 00:29:21 +01:00
|
|
|
static void RemoveFromDisk(const boost::filesystem::path &rootdir, const Key &key);
|
2014-12-09 17:19:59 +01:00
|
|
|
|
|
|
|
const void *data() const override;
|
2015-03-04 20:47:02 +01:00
|
|
|
void write(const void *source, uint64_t offset, uint64_t size) override;
|
2014-12-09 17:19:59 +01:00
|
|
|
|
|
|
|
void flush() override;
|
|
|
|
|
|
|
|
size_t size() const override;
|
|
|
|
|
|
|
|
private:
|
|
|
|
const boost::filesystem::path _filepath;
|
|
|
|
Data _data;
|
2015-03-05 22:16:57 +01:00
|
|
|
bool _dataChanged;
|
2014-12-09 17:19:59 +01:00
|
|
|
|
2015-04-18 14:47:12 +02:00
|
|
|
OnDiskBlock(const Key &key, const boost::filesystem::path &filepath, Data data);
|
2014-12-09 17:19:59 +01:00
|
|
|
|
|
|
|
void _fillDataWithZeroes();
|
|
|
|
void _storeToDisk() const;
|
|
|
|
|
|
|
|
DISALLOW_COPY_AND_ASSIGN(OnDiskBlock);
|
|
|
|
};
|
|
|
|
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
#endif
|