* newly provided data. More sophisticated implementations of
* ObjectStore will omit the untouched data and store it as a
* "hole" in the file.
+ *
+ * Note that a 0-length write does not affect the size of the object.
*/
void write(const coll_t& cid, const ghobject_t& oid, uint64_t off, uint64_t len,
const bufferlist& write_data, uint32_t flags = 0) {
* zero out the indicated byte range within an object. Some
* ObjectStore instances may optimize this to release the
* underlying storage space.
+ *
+ * If the zero range extends beyond the end of the object, the object
+ * size is extended, just as if we were writing a buffer full of zeros.
+ * EXCEPT if the length is 0, in which case (just like a 0-length write)
+ * we do not adjust the object size.
*/
void zero(const coll_t& cid, const ghobject_t& oid, uint64_t off, uint64_t len) {
Op* _op = _get_next_op();
}
+TEST_P(StoreTest, ZeroVsObjectSize) {
+ ObjectStore::Sequencer osr("test");
+ int r;
+ coll_t cid;
+ struct stat stat;
+ ghobject_t hoid(hobject_t(sobject_t("foo", CEPH_NOSNAP)));
+ {
+ ObjectStore::Transaction t;
+ t.create_collection(cid, 0);
+ cerr << "Creating collection " << cid << std::endl;
+ r = apply_transaction(store, &osr, std::move(t));
+ ASSERT_EQ(r, 0);
+ }
+ bufferlist a;
+ a.append("stuff");
+ {
+ ObjectStore::Transaction t;
+ t.write(cid, hoid, 0, 5, a);
+ r = apply_transaction(store, &osr, std::move(t));
+ ASSERT_EQ(r, 0);
+ }
+ ASSERT_EQ(0, store->stat(cid, hoid, &stat));
+ ASSERT_EQ(5, stat.st_size);
+ {
+ ObjectStore::Transaction t;
+ t.zero(cid, hoid, 1, 2);
+ r = apply_transaction(store, &osr, std::move(t));
+ ASSERT_EQ(r, 0);
+ }
+ ASSERT_EQ(0, store->stat(cid, hoid, &stat));
+ ASSERT_EQ(5, stat.st_size);
+ {
+ ObjectStore::Transaction t;
+ t.zero(cid, hoid, 3, 200);
+ r = apply_transaction(store, &osr, std::move(t));
+ ASSERT_EQ(r, 0);
+ }
+ ASSERT_EQ(0, store->stat(cid, hoid, &stat));
+ ASSERT_EQ(203, stat.st_size);
+ {
+ ObjectStore::Transaction t;
+ t.zero(cid, hoid, 100000, 200);
+ r = apply_transaction(store, &osr, std::move(t));
+ ASSERT_EQ(r, 0);
+ }
+ ASSERT_EQ(0, store->stat(cid, hoid, &stat));
+ ASSERT_EQ(100200, stat.st_size);
+}
+
TEST_P(StoreTest, ZeroLengthWrite) {
ObjectStore::Sequencer osr("test");
int r;
ASSERT_EQ(0, r);
}
+TEST_P(StoreTest, ZeroLengthZero) {
+ ObjectStore::Sequencer osr("test");
+ int r;
+ coll_t cid;
+ ghobject_t hoid(hobject_t(sobject_t("foo", CEPH_NOSNAP)));
+ {
+ ObjectStore::Transaction t;
+ t.create_collection(cid, 0);
+ t.touch(cid, hoid);
+ r = apply_transaction(store, &osr, std::move(t));
+ ASSERT_EQ(0, r);
+ }
+ {
+ ObjectStore::Transaction t;
+ t.zero(cid, hoid, 1048576, 0);
+ r = apply_transaction(store, &osr, std::move(t));
+ ASSERT_EQ(0, r);
+ }
+ struct stat stat;
+ r = store->stat(cid, hoid, &stat);
+ ASSERT_EQ(0, r);
+ ASSERT_EQ(0, stat.st_size);
+
+ bufferlist newdata;
+ r = store->read(cid, hoid, 0, 1048576, newdata);
+ ASSERT_EQ(0, r);
+}
+
TEST_P(StoreTest, SimpleAttrTest) {
ObjectStore::Sequencer osr("test");
int r;