Commit 40adb7e0 authored by Sebastien Gougeaud's avatar Sebastien Gougeaud Committed by Thomas Leibovici
Browse files

cli: add a '-l/--layout' option for put/mput commands



Instead of using the PHOBOS_STORE_default_layout env variable, users
can now indicate which layout they want to use to store their data
using the '-l' option of put/mput commands.

Change-Id: I2c52a791bf4b44af2dc0f6326f163d53b219d8ac
Signed-off-by: default avatarSebastien Gougeaud <sebastien.gougeaud@cea.fr>
Reviewed-on: https://cws-fleury.labs.ocre.cea.fr/gerrit/6662


Reviewed-by: Linter
Tested-by: default avatarJenkins s8open_nr <s8open_nr@ccc.ocre.cea.fr>
Reviewed-by: default avatarPatrice LUCAS <patrice.lucas@cea.fr>
Reviewed-by: default avatarThomas Leibovici <thomas.leibovici@cea.fr>
parent 37ccdb7a
......@@ -278,6 +278,36 @@ put commands:
phobos put -f dir file.in obj123
```
### Storage layouts
For now, phobos supports 2 storage layouts: simple and raid1 (for mirroring).
The default layout to use when data is written can be specified in the phobos
configuration file:
```
[store]
# indicate 'simple' or 'raid1' layout
default_layout = simple
```
Alternatively, you can override this value by using the '-l' option of your
put commands:
```
# put data using a raid1 layout
phobos put -l raid1 file.in obj123
```
Layouts can have additional parameters. For now, the only additional parameter
is for raid1 number of replicas. This is for now specified using the following
env variable:
```
# put data using a raid1 layout with 3 replicas
PHOBOS_LAYOUT_RAID1_repl_count=3 phobos put -l raid1 file.in obj123
```
### Configuring device and media types
#### Supported tape models
......
......@@ -291,6 +291,8 @@ class StoreGenericPutHandler(XferOptHandler):
choices=map(rsc_family2str,
ResourceFamily.__members__.values()),
help='Targeted storage family')
parser.add_argument('-l', '--layout', choices=["simple", "raid1"],
help='Desired storage layout')
class StorePutHandler(StoreGenericPutHandler):
......@@ -316,14 +318,15 @@ class StorePutHandler(StoreGenericPutHandler):
if attrs is not None:
attrs = attr_convert(attrs)
self.logger.debug("Loaded attributes set %r", attrs)
tags = self.params.get('tags', [])
tags = self.params.get('tags', [])
family = self.params.get('family')
layout = self.params.get('layout')
self.logger.debug("Inserting object '%s' to 'objid:%s'", src, oid)
self.client.put_register(oid, src, family=family, attrs=attrs,
tags=tags)
self.client.put_register(oid, src, family=family, layout=layout,
attrs=attrs, tags=tags)
try:
self.client.run()
except IOError as err:
......@@ -352,9 +355,10 @@ class StoreMPutHandler(StoreGenericPutHandler):
fin = sys.stdin
else:
fin = open(path)
tags = self.params.get('tags', [])
tags = self.params.get('tags', [])
family = self.params.get('family', [])
layout = self.params.get('layout', [])
for i, line in enumerate(fin):
# Skip empty lines and comments
......@@ -378,8 +382,8 @@ class StoreMPutHandler(StoreGenericPutHandler):
self.logger.debug("Loaded attributes set %r", attrs)
self.logger.debug("Inserting object '%s' to 'objid:%s'", src, oid)
self.client.put_register(oid, src, family=family, attrs=attrs,
tags=tags)
self.client.put_register(oid, src, family=family, layout=layout,
attrs=attrs, tags=tags)
if fin is not sys.stdin:
fin.close()
......
......@@ -132,15 +132,15 @@ class XferDescriptor(Structure):
the opened file.
"""
self.xd_objid = desc[0]
self.xd_op = desc[6]
self.xd_layout_name = 0
self.xd_op = desc[7]
self.xd_layout_name = desc[3]
self.xd_family = desc[2]
self.xd_flags = desc[4]
self.xd_tags = Tags(desc[5])
self.xd_flags = desc[5]
self.xd_tags = Tags(desc[6])
self.xd_rc = 0
if desc[3]:
for k, v in desc[3].iteritems():
if desc[4]:
for k, v in desc[4].iteritems():
rc = LIBPHOBOS.pho_attr_set(byref(self.xd_attrs),
str(k), str(v))
if rc:
......@@ -219,21 +219,22 @@ class Client(object):
def getmd_register(self, oid, data_path, attrs=None):
"""Enqueue a GETMD transfer."""
self.getmd_session.append((oid, data_path, -1, attrs, 0, None,
self.getmd_session.append((oid, data_path, -1, 0, attrs, 0, None,
PHO_XFER_OP_GETMD))
def get_register(self, oid, data_path, attrs=None):
"""Enqueue a GET transfer."""
self.get_session.append((oid, data_path, -1, attrs, 0, None,
self.get_session.append((oid, data_path, -1, 0, attrs, 0, None,
PHO_XFER_OP_GET))
def put_register(self, oid, data_path, family=None, attrs=None, tags=None):
def put_register(self, oid, data_path, family=None, layout=None, attrs=None,
tags=None):
"""Enqueue a PUT transfert."""
if family is None:
family = cfg_get_val("store", "default_family")
self.put_session.append((oid, data_path, str2rsc_family(family), attrs,
0, tags, PHO_XFER_OP_PUT))
self.put_session.append((oid, data_path, str2rsc_family(family), layout,
attrs, 0, tags, PHO_XFER_OP_PUT))
def clear(self):
"""Release resources associated to the current queues."""
......
......@@ -21,6 +21,10 @@
# along with Phobos. If not, see <http://www.gnu.org/licenses/>.
#
# TODO: change the way the resources are managed through the acceptance
# test cases: maybe considering all are locked, and only unlocking
# resources the test need at start, and relocking them when the test ends
set -xe
LOG_VALG="$LOG_COMPILER $LOG_FLAGS"
......@@ -248,6 +252,43 @@ function put_family
error "Put with family should have written object on a family medium"
}
function put_layout
{
local PSQL="psql phobos phobos"
local id1=test/hosts-lay1.$$
local id2=test/hosts-lay2.$$
local request1="SELECT lyt_info FROM extent WHERE oid='$id1';"
local request2="SELECT lyt_info FROM extent WHERE oid='$id2';"
# unlock enough resources to make the test:
# - only the second dir, the first one is already unlocked
# - not needed for tapes, as only one among eight is locked
# XXX: will also unlock a tape drive when lock admin on drives
# will be considered by daemon scheduler
if [[ $PHOBOS_STORE_default_family == "dir" ]]; then
$LOG_VALG $phobos dir unlock /tmp/test.pho.2
fi
# phobos put
$LOG_VALG $phobos put -l simple /etc/hosts $id1
$LOG_VALG $phobos put -l raid1 /etc/hosts $id2
# PSQL command to get the extent layout info
# XXX: will be replaced by a 'phobos object list' when implemented
$PSQL -t -c "$request1" | grep -q "\"name\": \"simple\"" ||
error "Put with simple layout should have written object using " \
"a simple layout"
$PSQL -t -c "$request2" | grep -q "\"name\": \"raid1\"" ||
error "Put with raid1 layout should have written object using " \
"a raid1 layout"
# relock resources we previously unlocked
if [[ $PHOBOS_STORE_default_family == "dir" ]]; then
$LOG_VALG $phobos dir lock /tmp/test.pho.2
fi
}
# Test tag based media selection
function put_tags
{
......@@ -493,6 +534,7 @@ trap cleanup EXIT
dir_setup
put_get_test
put_family dir
put_layout
put_tags
concurrent_put
check_status dir "$dirs"
......
Supports Markdown
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