Skip to content

Commit

Permalink
Make stale_reads_ok an argument of __init__
Browse files Browse the repository at this point in the history
Actually, stale_reads_ok is already an argument, but for some
reason it was not used anywhere in the code. So, just use it.
We borrow the existing code from the object server, which uses
setdefault(). We don't really need it, and could simply use
kwargs['stale_reads_ok']=stale_reads_ok, but let's keep the
divergencies down.

This was prompted by the desire to document the API of DB Broker
for the LFS work, and finding that documenting magical assignments
was a pain.

Change-Id: Id8f83358ad7709f0df826fbc520b3dfba026a2f1
  • Loading branch information
zaitcev committed Jul 21, 2013
1 parent 0fdad0d commit b84afc5
Show file tree
Hide file tree
Showing 2 changed files with 17 additions and 13 deletions.
14 changes: 8 additions & 6 deletions swift/account/server.py
Original file line number Diff line number Diff line change
Expand Up @@ -60,11 +60,13 @@ def __init__(self, conf):
swift.common.db.DB_PREALLOCATION = \
config_true_value(conf.get('db_preallocation', 'f'))

def _get_account_broker(self, drive, part, account):
def _get_account_broker(self, drive, part, account, **kwargs):
hsh = hash_path(account)
db_dir = storage_directory(DATADIR, part, hsh)
db_path = os.path.join(self.root, drive, db_dir, hsh + '.db')
return AccountBroker(db_path, account=account, logger=self.logger)
kwargs.setdefault('account', account)
kwargs.setdefault('logger', self.logger)
return AccountBroker(db_path, **kwargs)

def _deleted_response(self, broker, req, resp, body=''):
# We are here since either the account does not exist or
Expand Down Expand Up @@ -188,9 +190,9 @@ def HEAD(self, req):
return HTTPNotAcceptable(request=req)
if self.mount_check and not check_mount(self.root, drive):
return HTTPInsufficientStorage(drive=drive, request=req)
broker = self._get_account_broker(drive, part, account)
broker = self._get_account_broker(drive, part, account,
stale_reads_ok=True)
broker.pending_timeout = 0.1
broker.stale_reads_ok = True
if broker.is_deleted():
return self._deleted_response(broker, req, HTTPNotFound)
info = broker.get_info()
Expand Down Expand Up @@ -241,9 +243,9 @@ def GET(self, req):

if self.mount_check and not check_mount(self.root, drive):
return HTTPInsufficientStorage(drive=drive, request=req)
broker = self._get_account_broker(drive, part, account)
broker = self._get_account_broker(drive, part, account,
stale_reads_ok=True)
broker.pending_timeout = 0.1
broker.stale_reads_ok = True
if broker.is_deleted():
return self._deleted_response(broker, req, HTTPNotFound)
return account_listing_response(account, req, out_content_type, broker,
Expand Down
16 changes: 9 additions & 7 deletions swift/container/server.py
Original file line number Diff line number Diff line change
Expand Up @@ -74,7 +74,7 @@ def __init__(self, conf):
swift.common.db.DB_PREALLOCATION = \
config_true_value(conf.get('db_preallocation', 'f'))

def _get_container_broker(self, drive, part, account, container):
def _get_container_broker(self, drive, part, account, container, **kwargs):
"""
Get a DB broker for the container.
Expand All @@ -87,8 +87,10 @@ def _get_container_broker(self, drive, part, account, container):
hsh = hash_path(account, container)
db_dir = storage_directory(DATADIR, part, hsh)
db_path = os.path.join(self.root, drive, db_dir, hsh + '.db')
return ContainerBroker(db_path, account=account, container=container,
logger=self.logger)
kwargs.setdefault('account', account)
kwargs.setdefault('container', container)
kwargs.setdefault('logger', self.logger)
return ContainerBroker(db_path, **kwargs)

def account_update(self, req, account, container, broker):
"""
Expand Down Expand Up @@ -310,9 +312,9 @@ def HEAD(self, req):
return HTTPNotAcceptable(request=req)
if self.mount_check and not check_mount(self.root, drive):
return HTTPInsufficientStorage(drive=drive, request=req)
broker = self._get_container_broker(drive, part, account, container)
broker = self._get_container_broker(drive, part, account, container,
stale_reads_ok=True)
broker.pending_timeout = 0.1
broker.stale_reads_ok = True
if broker.is_deleted():
return HTTPNotFound(request=req)
info = broker.get_info()
Expand Down Expand Up @@ -390,9 +392,9 @@ def GET(self, req):
return HTTPNotAcceptable(request=req)
if self.mount_check and not check_mount(self.root, drive):
return HTTPInsufficientStorage(drive=drive, request=req)
broker = self._get_container_broker(drive, part, account, container)
broker = self._get_container_broker(drive, part, account, container,
stale_reads_ok=True)
broker.pending_timeout = 0.1
broker.stale_reads_ok = True
if broker.is_deleted():
return HTTPNotFound(request=req)
info = broker.get_info()
Expand Down

0 comments on commit b84afc5

Please sign in to comment.