Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion proto
38 changes: 21 additions & 17 deletions src/cache/benchmark/factory.cc
Original file line number Diff line number Diff line change
Expand Up @@ -25,24 +25,23 @@
#include "cache/benchmark/option.h"
#include "cache/utils/context.h"
#include "cache/utils/helper.h"
#include "common/block/block_context.h"

namespace dingofs {
namespace cache {

BlockKeyIterator::BlockKeyIterator(uint64_t idx, uint64_t fsid, uint64_t ino,
uint64_t blksize, uint64_t blocks)
BlockKeyIterator::BlockKeyIterator(uint64_t idx, uint64_t blksize,
uint64_t blocks)
: idx_(idx),
fsid_(fsid),
ino_(ino),
blksize_(blksize),
blocks_(blocks),
chunkid_((idx_ * blocks) + 1),
blockidx_(0),
id_((idx_ * blocks) + 1),
index_(0),
allocated_(0) {}

void BlockKeyIterator::SeekToFirst() {
chunkid_ = idx_ * blocks_ + 1;
blockidx_ = 0;
id_ = idx_ * blocks_ + 1;
index_ = 0;
}

bool BlockKeyIterator::Valid() const { return allocated_ < blocks_; }
Expand All @@ -55,15 +54,16 @@ void BlockKeyIterator::Next() {
return;
}

blockidx_++;
if (blockidx_ == kBlocksPerChunk) {
chunkid_++;
blockidx_ = 0;
index_++;
if (index_ == kBlocksPerChunk) {
id_++;
index_ = 0;
}
}

BlockKey BlockKeyIterator::Key() const {
return BlockKey(fsid_, ino_, chunkid_, blockidx_, 0);
return BlockKey(id_, static_cast<uint32_t>(index_),
static_cast<uint32_t>(blksize_));
}

constexpr uint64_t pagesize = 64 * 1024;
Expand Down Expand Up @@ -93,7 +93,8 @@ void PutTaskFactory::Put(const BlockKey& key) {
auto option = PutOption();
option.writeback = FLAGS_writeback;

auto status = block_cache_->Put(NewContext(), key, block_, option);
BlockContext block_ctx(key, static_cast<uint32_t>(FLAGS_fsid));
auto status = block_cache_->Put(NewContext(), block_ctx, block_, option);
if (!status.ok()) {
LOG(ERROR) << "Put block (key= " << key.Filename()
<< ") failed: " << status.ToString();
Expand Down Expand Up @@ -123,10 +124,13 @@ void RangeTaskFactory::RangeAll(const BlockKey& key) {
void RangeTaskFactory::Range(const BlockKey& key, off_t offset, size_t length,
IOBuffer* buffer) {
auto option = RangeOption();
option.retrive = FLAGS_retrive;
option.block_size = FLAGS_blksize;
option.retrieve_storage = FLAGS_retrive;
option.block_whole_length = FLAGS_blksize;

BlockContext block_ctx(key, static_cast<uint32_t>(FLAGS_fsid));
auto status =
block_cache_->Range(NewContext(), key, offset, length, buffer, option);
block_cache_->Range(NewContext(), block_ctx, offset, length, buffer,
option);

if (!status.ok()) {
LOG(ERROR) << "Range block (key=" << key.Filename()
Expand Down
10 changes: 4 additions & 6 deletions src/cache/benchmark/factory.h
Original file line number Diff line number Diff line change
Expand Up @@ -24,15 +24,15 @@
#define DINGOFS_SRC_CACHE_BENCHMARK_FACTORY_H_

#include "cache/blockcache/block_cache.h"
#include "common/block/block_context.h"

namespace dingofs {
namespace cache {

// block key iterator
class BlockKeyIterator {
public:
BlockKeyIterator(uint64_t idx, uint64_t fsid, uint64_t ino, uint64_t blksize,
uint64_t blocks);
BlockKeyIterator(uint64_t idx, uint64_t blksize, uint64_t blocks);

void SeekToFirst();
bool Valid() const;
Expand All @@ -43,12 +43,10 @@ class BlockKeyIterator {
static constexpr uint64_t kBlocksPerChunk = 16;

uint64_t idx_; // worker index, start with 0
uint64_t fsid_;
uint64_t ino_;
uint64_t blksize_;
uint64_t blocks_;
uint64_t chunkid_;
uint64_t blockidx_;
uint64_t id_; // slice id
uint64_t index_; // block index within the slice
uint64_t allocated_;
};

Expand Down
3 changes: 1 addition & 2 deletions src/cache/benchmark/worker.cc
Original file line number Diff line number Diff line change
Expand Up @@ -38,8 +38,7 @@ void Worker::Start() { ExecAllTasks(); }
void Worker::Shutdown() { countdown_.wait(); }

void Worker::ExecAllTasks() {
BlockKeyIterator iter(idx_, FLAGS_fsid, FLAGS_ino, FLAGS_blksize,
FLAGS_blocks);
BlockKeyIterator iter(idx_, FLAGS_blksize, FLAGS_blocks);

for (iter.SeekToFirst(); iter.Valid(); iter.Next()) {
auto task = factory_->GenTask(iter.Key());
Expand Down
26 changes: 16 additions & 10 deletions src/cache/blockcache/block_cache.h
Original file line number Diff line number Diff line change
Expand Up @@ -30,6 +30,7 @@

#include "cache/blockcache/cache_store.h"
#include "cache/common/context.h"
#include "common/block/block_context.h"
#include "common/io_buffer.h"
#include "common/status.h"

Expand Down Expand Up @@ -61,41 +62,43 @@ class BlockCache {
virtual Status Shutdown() { return Status::OK(); }

// block operations (sync)
virtual Status Put(ContextSPtr /*ctx*/, const BlockKey& /*key*/,
virtual Status Put(ContextSPtr /*ctx*/, const BlockContext& /*block_ctx*/,
const Block& /*block*/,
[[maybe_unused]] PutOption option = PutOption()) {
return Status::NotSupport("not implemented");
}

virtual Status Range(ContextSPtr /*ctx*/, const BlockKey& /*key*/,
virtual Status Range(ContextSPtr /*ctx*/, const BlockContext& /*block_ctx*/,
off_t /*offset*/, size_t /*length*/,
IOBuffer* /*buffer*/,
[[maybe_unused]] RangeOption option = RangeOption()) {
return Status::NotSupport("not implemented");
}

virtual Status Cache(ContextSPtr /*ctx*/, const BlockKey& /* key*/,
virtual Status Cache(ContextSPtr /*ctx*/, const BlockContext& /*block_ctx*/,
const Block& /*block*/,
[[maybe_unused]] CacheOption option = CacheOption()) {
return Status::NotSupport("not implemented");
}

virtual Status Prefetch(
ContextSPtr /*ctx*/, const BlockKey& /*key*/, size_t /*length*/,
ContextSPtr /*ctx*/, const BlockContext& /*block_ctx*/,
size_t /*length*/,
[[maybe_unused]] PrefetchOption option = PrefetchOption()) {
return Status::NotSupport("not implemented");
}

// block operations (async)
virtual void AsyncPut(ContextSPtr /*ctx*/, const BlockKey& /*key*/,
virtual void AsyncPut(ContextSPtr /*ctx*/, const BlockContext& /*block_ctx*/,
const Block& /*block*/, AsyncCallback cb,
[[maybe_unused]] PutOption option = PutOption()) {
if (cb) {
cb(Status::NotSupport("not implemented"));
}
}

virtual void AsyncRange(ContextSPtr /*ctx*/, const BlockKey& /*key*/,
virtual void AsyncRange(ContextSPtr /*ctx*/,
const BlockContext& /*block_ctx*/,
off_t /*offset*/, size_t /*length*/,
IOBuffer* /*buffer*/, AsyncCallback cb,
[[maybe_unused]] RangeOption option = RangeOption()) {
Expand All @@ -104,7 +107,8 @@ class BlockCache {
}
}

virtual void AsyncCache(ContextSPtr /*ctx*/, const BlockKey& /*key*/,
virtual void AsyncCache(ContextSPtr /*ctx*/,
const BlockContext& /*block_ctx*/,
const Block& /*block*/, AsyncCallback cb,
[[maybe_unused]] CacheOption option = CacheOption()) {
if (cb) {
Expand All @@ -113,8 +117,8 @@ class BlockCache {
}

virtual void AsyncPrefetch(
ContextSPtr /*ctx*/, const BlockKey& /*key*/, size_t /*length*/,
AsyncCallback cb,
ContextSPtr /*ctx*/, const BlockContext& /*block_ctx*/,
size_t /*length*/, AsyncCallback cb,
[[maybe_unused]] PrefetchOption option = PrefetchOption()) {
if (cb) {
cb(Status::NotSupport("not implemented"));
Expand All @@ -125,7 +129,9 @@ class BlockCache {
virtual bool IsEnabled() const { return false; }
virtual bool EnableStage() const { return false; }
virtual bool EnableCache() const { return false; }
virtual bool IsCached(const BlockKey& /*key*/) const { return false; }
virtual bool IsCached(const BlockContext& /*block_ctx*/) const {
return false;
}
virtual bool Dump(Json::Value& /*value*/) const { return true; }
};

Expand Down
Loading
Loading