From df66a76ce2fee20e91f0d3989bd758e2350f1ad5 Mon Sep 17 00:00:00 2001 From: Vitaliy Filippov Date: Tue, 25 Feb 2020 22:52:03 +0300 Subject: [PATCH] ...and make it work :) --- osd_primary.cpp | 7 +++++-- osd_receive.cpp | 12 +++++++++--- osd_test.cpp | 28 +++++++++++++++++++++++++++- 3 files changed, 41 insertions(+), 6 deletions(-) diff --git a/osd_primary.cpp b/osd_primary.cpp index db281cfa..77ab8105 100644 --- a/osd_primary.cpp +++ b/osd_primary.cpp @@ -287,10 +287,14 @@ void osd_t::handle_primary_subop(osd_op_t *cur_op, int ok, uint64_t version) { continue_primary_read(cur_op); } - else + else if (cur_op->req.hdr.opcode == OSD_OP_WRITE) { continue_primary_write(cur_op); } + else if (cur_op->req.hdr.opcode == OSD_OP_SYNC) + { + continue_primary_sync(cur_op); + } } } @@ -447,7 +451,6 @@ resume_2: .oid = it->first.oid, .version = it->second, }; - last_start++; last_end++; } if (last_osd != 0) diff --git a/osd_receive.cpp b/osd_receive.cpp index 3d06d9d5..26136c89 100644 --- a/osd_receive.cpp +++ b/osd_receive.cpp @@ -106,14 +106,19 @@ void osd_t::handle_op_hdr(osd_client_t *cl) cur_op->buf = memalign(512, cur_op->req.sec_rw.len); cl->read_remaining = 0; } - else if (cur_op->req.hdr.opcode == OSD_OP_SECONDARY_WRITE || - cur_op->req.hdr.opcode == OSD_OP_SECONDARY_STABILIZE || - cur_op->req.hdr.opcode == OSD_OP_SECONDARY_ROLLBACK) + else if (cur_op->req.hdr.opcode == OSD_OP_SECONDARY_WRITE) { if (cur_op->req.sec_rw.len > 0) cur_op->buf = memalign(512, cur_op->req.sec_rw.len); cl->read_remaining = cur_op->req.sec_rw.len; } + else if (cur_op->req.hdr.opcode == OSD_OP_SECONDARY_STABILIZE || + cur_op->req.hdr.opcode == OSD_OP_SECONDARY_ROLLBACK) + { + if (cur_op->req.sec_stab.len > 0) + cur_op->buf = memalign(512, cur_op->req.sec_stab.len); + cl->read_remaining = cur_op->req.sec_stab.len; + } else if (cur_op->req.hdr.opcode == OSD_OP_READ) { if (cur_op->req.rw.len > 0) @@ -148,6 +153,7 @@ void osd_t::handle_reply_hdr(osd_client_t *cl) if (req_it == cl->sent_ops.end()) { // Command out of sync. Drop connection + printf("Client %d command out of sync: id %lu\n", cl->peer_fd, cur_op->req.hdr.id); stop_client(cl->peer_fd); return; } diff --git a/osd_test.cpp b/osd_test.cpp index 5f65b5b2..b67fc73b 100644 --- a/osd_test.cpp +++ b/osd_test.cpp @@ -25,6 +25,8 @@ void* test_primary_read(int connect_fd, uint64_t inode, uint64_t offset, uint64_ void test_primary_write(int connect_fd, uint64_t inode, uint64_t offset, uint64_t len, uint64_t pattern); +void test_primary_sync(int connect_fd); + void test_sync_stab_all(int connect_fd); int main0(int narg, char *args[]) @@ -68,7 +70,7 @@ int main1(int narg, char *args[]) return 0; } -int main(int narg, char *args[]) +int main2(int narg, char *args[]) { int connect_fd; // Cluster write (sync not implemented yet) @@ -92,6 +94,18 @@ int main(int narg, char *args[]) return 0; } +int main(int narg, char *args[]) +{ + int connect_fd; + // Cluster write (sync not implemented yet) + connect_fd = connect_osd("127.0.0.1", 11203); + test_primary_write(connect_fd, 2, 0, 128*1024, PATTERN0); + test_primary_write(connect_fd, 2, 128*1024, 128*1024, PATTERN1); + test_primary_sync(connect_fd); + close(connect_fd); + return 0; +} + int connect_osd(const char *osd_address, int osd_port) { struct sockaddr_in addr; @@ -228,6 +242,18 @@ void test_primary_write(int connect_fd, uint64_t inode, uint64_t offset, uint64_ assert(check_reply(r, op, reply, len)); } +void test_primary_sync(int connect_fd) +{ + osd_any_op_t op; + osd_any_reply_t reply; + op.hdr.magic = SECONDARY_OSD_OP_MAGIC; + op.hdr.id = 1; + op.hdr.opcode = OSD_OP_SYNC; + write_blocking(connect_fd, op.buf, OSD_PACKET_SIZE); + int r = read_blocking(connect_fd, reply.buf, OSD_PACKET_SIZE); + assert(check_reply(r, op, reply, 0)); +} + void test_sync_stab_all(int connect_fd) { osd_any_op_t op;