Skip to content
Merged
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
16 changes: 12 additions & 4 deletions src/osd/PrimaryLogPG.cc
Original file line number Diff line number Diff line change
Expand Up @@ -6746,6 +6746,8 @@ int PrimaryLogPG::do_osd_ops(OpContext *ctx, vector<OSDOp>& ops)
truncate_update_size_and_usage(ctx->delta_stats,
oi,
op.extent.truncate_size);
//truncate modify oi.size, need clear old data_digest and DIGEST flag

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

In this case the logic is a little bit different than in CEPH_OSD_OP_TRUNCATE:

          if (op.extent.truncate_seq) {
           ceph_assert(op.extent.offset == op.extent.truncate_size);  // <------------------
            if (op.extent.truncate_seq <= oi.truncate_seq) {
              dout(10) << " truncate seq " << op.extent.truncate_seq << " <= current " << oi.truncate_seq
                       << ", no-op" << dendl;
              break; // old
            }
            dout(10) << " truncate seq " << op.extent.truncate_seq << " > current " << oi.truncate_seq
                     << ", truncating" << dendl;
            oi.truncate_seq = op.extent.truncate_seq;
            oi.truncate_size = op.extent.truncate_size;
          }
          // ...
         if (op.extent.offset != oi.size) { // <----------
            truncate_update_size_and_usage(ctx->delta_stats,
                                           oi,
                                           op.extent.offset);
          }
          ctx->delta_stats.num_wr++;
          // do no set exists, or we will break above DELETE -> TRUNCATE munging.
  
          oi.clear_data_digest(); // <-------

The difference is what happens in the op.extent.truncate_size == oi.size case: CEPH_OSD_OP_TRUNCATE clears the digest; CEPH_OSD_OP_WRITE – does not.

I think the reason is that the trunc-like write differs from regular trunc. The former puts truncate into the transaction when expanding the object; for shrinking (or keeping same) only nop + update of object_info happens – the data is untouched. Therefore preserving the digest for op.extent.truncate_size == oi.size should be fine.

          if (op.extent.length == 0) {
            if (op.extent.offset > oi.size) {
              t->truncate(
                soid, op.extent.offset);
              truncate_update_size_and_usage(ctx->delta_stats, oi,
                                             op.extent.offset);
            } else {
              t->nop(soid);
            }
          } else {
            t->write(
              soid, op.extent.offset, op.extent.length, osd_op.indata, op.flags);
          }

oi.clear_data_digest();
Comment thread
rzarzynski marked this conversation as resolved.
Resolved
}
} else {
dout(10) << " truncate_seq " << op.extent.truncate_seq << " > current " << seq
Expand All @@ -6764,10 +6766,16 @@ int PrimaryLogPG::do_osd_ops(OpContext *ctx, vector<OSDOp>& ops)

if (op.extent.length == 0) {
if (op.extent.offset > oi.size) {
t->truncate(
soid, op.extent.offset);
truncate_update_size_and_usage(ctx->delta_stats, oi,
op.extent.offset);
if (seq && (seq > op.extent.truncate_seq)) {
//do nothing
//write arrived after truncate, we should not truncate to offset
} else {
t->truncate(
soid, op.extent.offset);
truncate_update_size_and_usage(ctx->delta_stats, oi,
op.extent.offset);
oi.clear_data_digest();
}
} else {
t->nop(soid);
}
Expand Down
28 changes: 28 additions & 0 deletions src/test/librados/io_cxx.cc
Original file line number Diff line number Diff line change
Expand Up @@ -495,6 +495,18 @@ TEST_F(LibRadosIoPP, XattrListPP) {
}
}

TEST_F(LibRadosIoPP, CrcZeroWrite) {
char buf[128];

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

crimson lacks the fix, so I expect this test to fail there. Might we worth adding at a comment at least.

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

It's a simple fix -- can we just go ahead and fix it in crimson rather than letting the test fail?

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

actually, i tested it on crimson and it pass

@petrutlucian94 petrutlucian94 May 24, 2024 •

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This test fails sporadically with ENOTSUP:

$ ./ceph_test_rados_api_io_pp
# ...
/mnt/data/workspace/ceph_linux/src/test/librados/io_cxx.cc:888: Failure
Expected equality of these values:
  0
  ioctx.write("foo", bl, 0, sizeof(buf))
    Which is: -95
[  FAILED  ] LibRadosIoECPP.CrcZeroWrite (767 ms)

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I'm thinking about skipping it on Windows for the time being: ceph/ceph-win32-tests#19

bufferlist bl;

ASSERT_EQ(0, ioctx.write("foo", bl, 0, 0));
ASSERT_EQ(0, ioctx.write("foo", bl, 0, sizeof(buf)));

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Hmm, the only usage of the 0xcc-filled buf seems to be the sizeof(). Is that truly the intention?

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@rzarzynski yes, i had in mind to check that we didn't had any override above zero, but i didn't added it. i can remove the memset.

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@rzarzynski please review


ObjectReadOperation read;
read.read(0, bl.length(), NULL, NULL);
ASSERT_EQ(0, ioctx.operate("foo", &read, &bl));
}

TEST_F(LibRadosIoECPP, SimpleWritePP) {
SKIP_IF_CRIMSON();
char buf[128];
Expand Down Expand Up @@ -865,6 +877,22 @@ TEST_F(LibRadosIoECPP, RmXattrPP) {
ASSERT_EQ(-ENOENT, ioctx.rmxattr("foo_rmxattr", attr2));
}

TEST_F(LibRadosIoECPP, CrcZeroWrite) {
SKIP_IF_CRIMSON();
set_allow_ec_overwrites(pool_name, true);
char buf[128];
memset(buf, 0xcc, sizeof(buf));
bufferlist bl;

ASSERT_EQ(0, ioctx.write("foo", bl, 0, 0));
ASSERT_EQ(0, ioctx.write("foo", bl, 0, sizeof(buf)));

ObjectReadOperation read;
read.read(0, bl.length(), NULL, NULL);
ASSERT_EQ(0, ioctx.operate("foo", &read, &bl));
recreate_pool();
}

TEST_F(LibRadosIoECPP, XattrListPP) {
SKIP_IF_CRIMSON();
char buf[128];
Expand Down
15 changes: 15 additions & 0 deletions src/test/librados/test_cxx.cc
Original file line number Diff line number Diff line change
Expand Up @@ -121,6 +121,21 @@ std::string create_one_ec_pool_pp(const std::string &pool_name, Rados &cluster)
return "";
}

std::string set_allow_ec_overwrites_pp(const std::string &pool_name, Rados &cluster, bool allow)
{
std::ostringstream oss;
bufferlist inbl;
int ret = cluster.mon_command(
"{\"prefix\": \"osd pool set\", \"pool\": \"" + pool_name + "\", \"var\": \"allow_ec_overwrites\", \"val\": \"" + (allow ? "true" : "false") + "\"}",
inbl, NULL, NULL);
if (ret) {
cluster.shutdown();
oss << "mon_command osd pool set pool:" << pool_name << " pool_type:erasure allow_ec_overwrites true failed with error " << ret;
return oss.str();
}
return "";
}

std::string connect_cluster_pp(librados::Rados &cluster)
{
return connect_cluster_pp(cluster, {});
Expand Down
2 changes: 2 additions & 0 deletions src/test/librados/test_cxx.h
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,8 @@ std::string create_one_pool_pp(const std::string &pool_name,
const std::map<std::string, std::string> &config);
std::string create_one_ec_pool_pp(const std::string &pool_name,
librados::Rados &cluster);
std::string set_allow_ec_overwrites_pp(const std::string &pool_name,
librados::Rados &cluster, bool allow);
std::string connect_cluster_pp(librados::Rados &cluster);
std::string connect_cluster_pp(librados::Rados &cluster,
const std::map<std::string, std::string> &config);
Expand Down
13 changes: 12 additions & 1 deletion src/test/librados/testcase_cxx.cc
Original file line number Diff line number Diff line change
Expand Up @@ -193,7 +193,6 @@ Rados RadosTestPP::s_cluster;
void RadosTestPP::SetUpTestCase()
{
init_rand();

auto pool_prefix = fmt::format("{}_", ::testing::UnitTest::GetInstance()->current_test_case()->name());
pool_name = get_temp_pool_name(pool_prefix);
ASSERT_EQ("", create_one_pool_pp(pool_name, s_cluster));
Expand Down Expand Up @@ -405,3 +404,15 @@ void RadosTestECPP::TearDown()
ioctx.close();
}

void RadosTestECPP::recreate_pool()
{
SKIP_IF_CRIMSON();
ASSERT_EQ(0, destroy_one_ec_pool_pp(pool_name, s_cluster));
ASSERT_EQ("", create_one_ec_pool_pp(pool_name, s_cluster));
SetUp();
}

void RadosTestECPP::set_allow_ec_overwrites(std::string pool, bool allow)
{
ASSERT_EQ("", set_allow_ec_overwrites_pp(pool, cluster, allow));
}
2 changes: 2 additions & 0 deletions src/test/librados/testcase_cxx.h
Original file line number Diff line number Diff line change
Expand Up @@ -117,6 +117,8 @@ class RadosTestECPP : public RadosTestPP {
protected:
static void SetUpTestCase();
static void TearDownTestCase();
void recreate_pool();
void set_allow_ec_overwrites(std::string pool, bool allow=true);
static librados::Rados s_cluster;
static std::string pool_name;

Expand Down
6 changes: 5 additions & 1 deletion src/test/pybind/test_rados.py
Original file line number Diff line number Diff line change
Expand Up @@ -312,8 +312,12 @@ def test_cmpext(self):
def test_list_objects_empty(self):
eq(list(self.ioctx.list_objects()), [])

def test_list_objects(self):
def test_read_crc(self):
self.ioctx.write('a', b'')
self.ioctx.write('a', b'', 5)
self.ioctx.read('a')

def test_list_objects(self):
self.ioctx.write('b', b'foo')
self.ioctx.write_full('c', b'bar')
self.ioctx.append('d', b'jazz')
Expand Down