ceph: fix write emulation

Ceph never raises ObjectNotFound on write.

Change-Id: Ida84fcbcb9fbd75b90eb11b57f3db271c1425102
This commit is contained in:
Julien Danjou 2016-08-20 10:32:34 +02:00
parent f1f81c552b
commit fc3838243a
3 changed files with 5 additions and 16 deletions

View File

@ -415,12 +415,6 @@ class AggregatedTimeSerie(TimeSerie):
return int((self.first.value - split) // (self.sampling * 10e8)
* self.SERIAL_LEN)
@staticmethod
def padding(offset):
offset = offset // AggregatedTimeSerie.SERIAL_LEN
pad = [False] * offset * 2
return struct.pack('<' + '?d' * offset, *pad)
def _truncate(self, quick=False):
"""Truncate the timeserie."""
if self.max_size is not None:

View File

@ -257,12 +257,7 @@ class CephStorage(_carbonara.CarbonaraBasedStorage):
granularity, data, offset=0, version=3):
name = self._get_object_name(metric, timestamp_key,
aggregation, granularity, version)
try:
self.ioctx.write(name, data, offset=offset)
except rados.ObjectNotFound:
# first time writing data
self.ioctx.write_full(
name, carbonara.AggregatedTimeSerie.padding(offset) + data)
self.ioctx.write(name, data, offset=offset)
self.ioctx.set_xattr("gnocchi_%s_container" % metric.id, name, "")
def _delete_metric_measures(self, metric, timestamp_key, aggregation,

View File

@ -140,11 +140,11 @@ class FakeRadosModule(object):
self._validate_key(key)
try:
current = self.kvs[key]
if len(current) < offset:
current += b'\x00' * (offset - len(current))
self.kvs[key] = current[:offset] + value
except KeyError:
raise FakeRadosModule.ObjectNotFound
current = b""
if len(current) < offset:
current += b'\x00' * (offset - len(current))
self.kvs[key] = current[:offset] + value
def stat(self, key):
self._validate_key(key)