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"
|
2015-04-25 02:48:41 +02:00
|
|
|
#include <messmer/cpp-utils/data/Data.h>
|
2014-12-09 17:19:59 +01:00
|
|
|
#include <iostream>
|
|
|
|
|
2015-07-20 18:57:48 +02:00
|
|
|
#include <messmer/cpp-utils/pointer/unique_ref.h>
|
2015-10-05 18:54:16 +02:00
|
|
|
#include <mutex>
|
2014-12-09 17:19:59 +01:00
|
|
|
|
|
|
|
namespace blockstore {
|
|
|
|
namespace ondisk {
|
|
|
|
class OnDiskBlockStore;
|
|
|
|
|
|
|
|
class OnDiskBlock: public Block {
|
|
|
|
public:
|
2015-07-20 18:57:48 +02:00
|
|
|
OnDiskBlock(const Key &key, const boost::filesystem::path &filepath, cpputils::Data data);
|
2014-12-09 17:19:59 +01:00
|
|
|
virtual ~OnDiskBlock();
|
|
|
|
|
2015-07-21 14:50:52 +02:00
|
|
|
static boost::optional<cpputils::unique_ref<OnDiskBlock>> LoadFromDisk(const boost::filesystem::path &rootdir, const Key &key);
|
2015-07-20 18:57:48 +02:00
|
|
|
static boost::optional<cpputils::unique_ref<OnDiskBlock>> CreateOnDisk(const boost::filesystem::path &rootdir, const Key &key, cpputils::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;
|
2015-04-25 02:48:41 +02:00
|
|
|
cpputils::Data _data;
|
2015-03-05 22:16:57 +01:00
|
|
|
bool _dataChanged;
|
2014-12-09 17:19:59 +01:00
|
|
|
|
|
|
|
void _fillDataWithZeroes();
|
|
|
|
void _storeToDisk() const;
|
|
|
|
|
2015-10-05 18:54:16 +02:00
|
|
|
std::mutex _mutex;
|
|
|
|
|
2014-12-09 17:19:59 +01:00
|
|
|
DISALLOW_COPY_AND_ASSIGN(OnDiskBlock);
|
|
|
|
};
|
|
|
|
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
#endif
|