Commit 2aed7232 authored by Sofia Papagiannaki's avatar Sofia Papagiannaki Committed by Chrysostomos Nanakos
Browse files

pithos: Slight modifications in the backends

* Do not generate/register a mapfile for zero size objects since
there are not stored in the storage backend.
* Several minor fixes
parent bbbc13c2
......@@ -771,7 +771,7 @@ class Node(DBWorker):
available=True, map_check_timestamp=None,
mapfile=None, is_snapshot=False):
"""Create a new version from the given properties.
Return the (serial, mtime) of the new version.
Return the (serial, mtime, mapfile) of the new version.
If mapfile is not None, set mapfile to this value.
Otherwise, assign to the mapfile a new unique identifier.
......@@ -780,6 +780,12 @@ class Node(DBWorker):
"""
mtime = time()
if size == 0:
mapfile = None
elif mapfile is None:
mapfile = functions.concat(literal(self.mapfile_prefix),
functions.next_value(self.mapfile_seq))
s = self.versions.insert().returning(self.versions.c.serial,
self.versions.c.mtime,
self.versions.c.mapfile)
......@@ -788,9 +794,7 @@ class Node(DBWorker):
mtime=mtime, muser=muser, uuid=uuid, checksum=checksum,
cluster=cluster, available=available,
map_check_timestamp=map_check_timestamp,
mapfile=(mapfile or
functions.concat(literal(self.mapfile_prefix),
functions.next_value(self.mapfile_seq))),
mapfile=mapfile,
is_snapshot=is_snapshot)
r = self.conn.execute(s)
serial, mtime, mapfile = r.fetchone()
......@@ -930,7 +934,6 @@ class Node(DBWorker):
update_statistics_ancestors_depth=None):
"""Move the version into another cluster."""
mtime = time()
props = self.version_get_properties(serial)
if not props:
return
......
......@@ -580,7 +580,9 @@ class Node(DBWorker):
Otherwise, assign to the mapfile a new unique identifier.
"""
if mapfile is None:
if size == 0:
mapfile = None
elif mapfile is None:
q = ("insert into mapfile_seq (dummy) values (?)")
serial = self.execute(q, (False,)).lastrowid
mapfile = ''.join([self.mapfile_prefix, unicode(serial)])
......@@ -632,8 +634,8 @@ class Node(DBWorker):
else:
cols = ("serial, node, hash, size, type, source, mtime, "
"muser, uuid, checksum, cluster, "
"available, map_check_timestamp,"
"mapfile, is_snapshot"),
"available, map_check_timestamp, "
"mapfile, is_snapshot")
q = q % (cols, subq)
self.execute(q, args + [cluster])
......@@ -667,10 +669,10 @@ class Node(DBWorker):
if keys:
cols = ','.join(k for k in keys if k in self._props)
else:
cols = ("serial, node, hash, size, type, source, mtime, "
"muser, uuid, checksum, cluster, "
"available, map_check_timestamp,"
"mapfile, is_snapshot")
cols = ("v.serial, v.node, v.hash, v.size, v.type, v.source, "
"v.mtime, v.muser, v.uuid, v.checksum, v.cluster, "
"v.available, v.map_check_timestamp,v.mapfile, "
"v.is_snapshot")
q = q % (cols, subq, "order by path" if order_by_path else "")
args += [cluster]
......@@ -687,7 +689,7 @@ class Node(DBWorker):
"""
props = props or self._props
keys = keys or props.keys
keys = keys or props.keys()
cols = ','.join(k for k in keys if k in props)
q = ("select %s from versions where serial = ? ") % cols
args = [serial]
......@@ -715,7 +717,7 @@ class Node(DBWorker):
if not props:
return
node = props[self.NODE]
size = props[self.IZE]
size = props[self.SIZE]
oldcluster = props[self.CLUSTER]
if cluster == oldcluster:
return
......
......@@ -1191,7 +1191,7 @@ class ModularBackend(BaseBackend):
"""Return the object's size and a list with partial hashes."""
self._can_read_object(user, account, container, name)
path, node = self._lookup_object(account, container, name)
props = self._get_version(node, version, keys=_propnames)
props = self._get_version(node, version)
return props[self.IS_SNAPSHOT], props[self.SIZE], \
self._get_object_hashmap(props, update_available=True)
......@@ -1486,8 +1486,7 @@ class ModularBackend(BaseBackend):
nodes = [elem[2] for elem in src_names]
# TODO: Will do another fetch of the properties
# in duplicate version...
props = self._get_versions(nodes,
keys=_propnames)
props = self._get_versions(nodes)
for prop, path, node in zip(props, paths, nodes):
src_version_id = prop[self.SERIAL]
......@@ -1967,7 +1966,7 @@ class ModularBackend(BaseBackend):
pre_version_id = None
props = self.node.version_lookup(node, inf, CLUSTER_NORMAL)
if props is not None:
pre_version_id = props.serial
pre_version_id = props[self.SERIAL]
if pre_version_id is not None:
self.node.version_recluster(pre_version_id, CLUSTER_HISTORY,
update_statistics_ancestors_depth)
......
Markdown is supported
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment