Try to submit a test write operation
parent
debaf6c943
commit
5b8df6768b
|
@ -59,6 +59,11 @@ blockstore::~blockstore()
|
||||||
free(journal.sector_info);
|
free(journal.sector_info);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
bool blockstore::is_started()
|
||||||
|
{
|
||||||
|
return initialized == 10;
|
||||||
|
}
|
||||||
|
|
||||||
// main event loop - produce requests
|
// main event loop - produce requests
|
||||||
void blockstore::loop()
|
void blockstore::loop()
|
||||||
{
|
{
|
||||||
|
|
|
@ -211,7 +211,7 @@ struct blockstore_operation
|
||||||
uint32_t offset;
|
uint32_t offset;
|
||||||
// For stabilize requests: buf contains <len> obj_ver_id's to stabilize
|
// For stabilize requests: buf contains <len> obj_ver_id's to stabilize
|
||||||
uint32_t len;
|
uint32_t len;
|
||||||
uint8_t *buf;
|
uint8_t *buf; // FIXME: void*
|
||||||
int retval;
|
int retval;
|
||||||
|
|
||||||
// FIXME: Move internal fields somewhere
|
// FIXME: Move internal fields somewhere
|
||||||
|
@ -325,6 +325,8 @@ public:
|
||||||
// Event loop
|
// Event loop
|
||||||
void loop();
|
void loop();
|
||||||
|
|
||||||
|
bool is_started();
|
||||||
|
|
||||||
// Returns true when it's safe to destroy the instance. If destroying the instance
|
// Returns true when it's safe to destroy the instance. If destroying the instance
|
||||||
// requires to purge some queues, starts that process. Should be called in the event
|
// requires to purge some queues, starts that process. Should be called in the event
|
||||||
// loop until it returns true.
|
// loop until it returns true.
|
||||||
|
|
|
@ -3,6 +3,9 @@
|
||||||
void blockstore::enqueue_write(blockstore_operation *op)
|
void blockstore::enqueue_write(blockstore_operation *op)
|
||||||
{
|
{
|
||||||
// Assign version number
|
// Assign version number
|
||||||
|
bool found = false;
|
||||||
|
if (dirty_db.size() > 0)
|
||||||
|
{
|
||||||
auto dirty_it = dirty_db.upper_bound((obj_ver_id){
|
auto dirty_it = dirty_db.upper_bound((obj_ver_id){
|
||||||
.oid = op->oid,
|
.oid = op->oid,
|
||||||
.version = UINT64_MAX,
|
.version = UINT64_MAX,
|
||||||
|
@ -10,9 +13,11 @@ void blockstore::enqueue_write(blockstore_operation *op)
|
||||||
dirty_it--;
|
dirty_it--;
|
||||||
if (dirty_it != dirty_db.end() && dirty_it->first.oid == op->oid)
|
if (dirty_it != dirty_db.end() && dirty_it->first.oid == op->oid)
|
||||||
{
|
{
|
||||||
|
found = true;
|
||||||
op->version = dirty_it->first.version + 1;
|
op->version = dirty_it->first.version + 1;
|
||||||
}
|
}
|
||||||
else
|
}
|
||||||
|
if (!found)
|
||||||
{
|
{
|
||||||
auto clean_it = clean_db.find(op->oid);
|
auto clean_it = clean_db.find(op->oid);
|
||||||
if (clean_it != clean_db.end())
|
if (clean_it != clean_db.end())
|
||||||
|
|
7
test.cpp
7
test.cpp
|
@ -212,10 +212,11 @@ int main(int argc, char *argv[])
|
||||||
{
|
{
|
||||||
std::map<int, std::string> strs;
|
std::map<int, std::string> strs;
|
||||||
strs.emplace(12, "str");
|
strs.emplace(12, "str");
|
||||||
auto it = strs.upper_bound(11);
|
auto it = strs.upper_bound(13);
|
||||||
printf("s = %d %s %d\n", it->first, it->second.c_str(), it == strs.begin());
|
//printf("s = %d %s %d\n", it->first, it->second.c_str(), it == strs.begin());
|
||||||
it--;
|
it--;
|
||||||
printf("s = %d %s\n", it->first, it->second.c_str());
|
printf("%d\n", it == strs.end());
|
||||||
|
//printf("s = %d %s\n", it->first, it->second.c_str());
|
||||||
struct io_uring ring;
|
struct io_uring ring;
|
||||||
int fd = open("/dev/loop0", O_RDWR | O_DIRECT, 0644);
|
int fd = open("/dev/loop0", O_RDWR | O_DIRECT, 0644);
|
||||||
if (fd < 0)
|
if (fd < 0)
|
||||||
|
|
|
@ -10,8 +10,9 @@ class timerfd_interval
|
||||||
int status;
|
int status;
|
||||||
ring_loop_t *ringloop;
|
ring_loop_t *ringloop;
|
||||||
ring_consumer_t consumer;
|
ring_consumer_t consumer;
|
||||||
|
std::function<void(void)> callback;
|
||||||
public:
|
public:
|
||||||
timerfd_interval(ring_loop_t *ringloop, int seconds)
|
timerfd_interval(ring_loop_t *ringloop, int seconds, std::function<void(void)> cb)
|
||||||
{
|
{
|
||||||
wait_state = 0;
|
wait_state = 0;
|
||||||
timerfd = timerfd_create(CLOCK_MONOTONIC, TFD_NONBLOCK);
|
timerfd = timerfd_create(CLOCK_MONOTONIC, TFD_NONBLOCK);
|
||||||
|
@ -30,6 +31,7 @@ public:
|
||||||
consumer.loop = [this]() { loop(); };
|
consumer.loop = [this]() { loop(); };
|
||||||
ringloop->register_consumer(consumer);
|
ringloop->register_consumer(consumer);
|
||||||
this->ringloop = ringloop;
|
this->ringloop = ringloop;
|
||||||
|
this->callback = cb;
|
||||||
}
|
}
|
||||||
|
|
||||||
~timerfd_interval()
|
~timerfd_interval()
|
||||||
|
@ -61,7 +63,7 @@ public:
|
||||||
uint64_t n;
|
uint64_t n;
|
||||||
read(timerfd, &n, 8);
|
read(timerfd, &n, 8);
|
||||||
wait_state = 0;
|
wait_state = 0;
|
||||||
printf("tick 1s\n");
|
callback();
|
||||||
};
|
};
|
||||||
wait_state = 1;
|
wait_state = 1;
|
||||||
ringloop->submit();
|
ringloop->submit();
|
||||||
|
@ -76,13 +78,33 @@ int main(int narg, char *args[])
|
||||||
config["data_device"] = "./test_data.bin";
|
config["data_device"] = "./test_data.bin";
|
||||||
ring_loop_t *ringloop = new ring_loop_t(512);
|
ring_loop_t *ringloop = new ring_loop_t(512);
|
||||||
blockstore *bs = new blockstore(config, ringloop);
|
blockstore *bs = new blockstore(config, ringloop);
|
||||||
// print "tick" every second
|
timerfd_interval tick_tfd(ringloop, 1, []()
|
||||||
timerfd_interval tick_tfd(ringloop, 1);
|
{
|
||||||
|
printf("tick 1s\n");
|
||||||
|
});
|
||||||
|
blockstore_operation op;
|
||||||
|
op.flags = OP_WRITE;
|
||||||
|
op.oid = { .inode = 1, .stripe = 0 };
|
||||||
|
op.version = 0;
|
||||||
|
op.offset = 4096;
|
||||||
|
op.len = 4096;
|
||||||
|
op.buf = (uint8_t*)memalign(512, 4096);
|
||||||
|
memset(op.buf, 0xaa, 4096);
|
||||||
|
op.callback = [](blockstore_operation *op)
|
||||||
|
{
|
||||||
|
printf("completed %d\n", op->retval);
|
||||||
|
};
|
||||||
|
bool bs_was_done = false;
|
||||||
while (true)
|
while (true)
|
||||||
{
|
{
|
||||||
|
bool bs_done = bs->is_started();
|
||||||
|
if (bs_done && !bs_was_done)
|
||||||
|
{
|
||||||
|
bs->enqueue_op(&op);
|
||||||
|
bs_was_done = true;
|
||||||
|
}
|
||||||
ringloop->loop(true);
|
ringloop->loop(true);
|
||||||
}
|
}
|
||||||
|
|
||||||
delete bs;
|
delete bs;
|
||||||
delete ringloop;
|
delete ringloop;
|
||||||
return 0;
|
return 0;
|
||||||
|
|
Loading…
Reference in New Issue