Skip to content

Commit

Permalink
Relocate DATADIR to backends
Browse files Browse the repository at this point in the history
It simply makes sense that the definition of DATADIR belongs to
backends. After all, some of them may not even have any.

Coincidentially, a few unnecessary imports are dropped.

By the way, on the object server side, diskfile.py provides DATADIR
in the same way already.

Change-Id: I60bfd522c77c4a0ee13697a2e31141777c7e2398
  • Loading branch information
zaitcev committed Apr 2, 2014
1 parent 429445d commit a7cfcc3
Show file tree
Hide file tree
Showing 14 changed files with 25 additions and 39 deletions.
6 changes: 2 additions & 4 deletions swift/account/auditor.py
Original file line number Diff line number Diff line change
Expand Up @@ -19,8 +19,7 @@
from random import random

import swift.common.db
from swift.account import server as account_server
from swift.account.backend import AccountBroker
from swift.account.backend import AccountBroker, DATADIR
from swift.common.utils import get_logger, audit_location_generator, \
config_true_value, dump_recon_cache, ratelimit_sleep
from swift.common.daemon import Daemon
Expand Down Expand Up @@ -49,8 +48,7 @@ def __init__(self, conf):
self.rcache = os.path.join(self.recon_cache_path, "account.recon")

def _one_audit_pass(self, reported):
all_locs = audit_location_generator(self.devices,
account_server.DATADIR, '.db',
all_locs = audit_location_generator(self.devices, DATADIR, '.db',
mount_check=self.mount_check,
logger=self.logger)
for path, device, partition in all_locs:
Expand Down
2 changes: 2 additions & 0 deletions swift/account/backend.py
Original file line number Diff line number Diff line change
Expand Up @@ -28,6 +28,8 @@
from swift.common.db import DatabaseBroker, DatabaseConnectionError, \
PENDING_CAP, PICKLE_PROTOCOL, utf8encode

DATADIR = 'accounts'


class AccountBroker(DatabaseBroker):
"""Encapsulates working with an account database."""
Expand Down
3 changes: 1 addition & 2 deletions swift/account/reaper.py
Original file line number Diff line number Diff line change
Expand Up @@ -23,8 +23,7 @@
from eventlet import GreenPool, sleep, Timeout

import swift.common.db
from swift.account.server import DATADIR
from swift.account.backend import AccountBroker
from swift.account.backend import AccountBroker, DATADIR
from swift.common.direct_client import direct_delete_container, \
direct_delete_object, direct_get_container
from swift.common.exceptions import ClientException
Expand Down
5 changes: 2 additions & 3 deletions swift/account/replicator.py
Original file line number Diff line number Diff line change
Expand Up @@ -13,13 +13,12 @@
# See the License for the specific language governing permissions and
# limitations under the License.

from swift.account import server as account_server
from swift.account.backend import AccountBroker
from swift.account.backend import AccountBroker, DATADIR
from swift.common import db_replicator


class AccountReplicator(db_replicator.Replicator):
server_type = 'account'
brokerclass = AccountBroker
datadir = account_server.DATADIR
datadir = DATADIR
default_port = 6002
5 changes: 1 addition & 4 deletions swift/account/server.py
Original file line number Diff line number Diff line change
Expand Up @@ -21,7 +21,7 @@
from eventlet import Timeout

import swift.common.db
from swift.account.backend import AccountBroker
from swift.account.backend import AccountBroker, DATADIR
from swift.account.utils import account_listing_response
from swift.common.db import DatabaseConnectionError, DatabaseAlreadyExists
from swift.common.request_helpers import get_param, get_listing_content_type, \
Expand All @@ -40,9 +40,6 @@
from swift.common.request_helpers import is_sys_or_user_meta


DATADIR = 'accounts'


class AccountController(object):
"""WSGI controller for the account server."""

Expand Down
6 changes: 2 additions & 4 deletions swift/container/auditor.py
Original file line number Diff line number Diff line change
Expand Up @@ -21,8 +21,7 @@
from eventlet import Timeout

import swift.common.db
from swift.container import server as container_server
from swift.container.backend import ContainerBroker
from swift.container.backend import ContainerBroker, DATADIR
from swift.common.utils import get_logger, audit_location_generator, \
config_true_value, dump_recon_cache, ratelimit_sleep
from swift.common.daemon import Daemon
Expand All @@ -49,8 +48,7 @@ def __init__(self, conf):
self.rcache = os.path.join(self.recon_cache_path, "container.recon")

def _one_audit_pass(self, reported):
all_locs = audit_location_generator(self.devices,
container_server.DATADIR, '.db',
all_locs = audit_location_generator(self.devices, DATADIR, '.db',
mount_check=self.mount_check,
logger=self.logger)
for path, device, partition in all_locs:
Expand Down
2 changes: 2 additions & 0 deletions swift/container/backend.py
Original file line number Diff line number Diff line change
Expand Up @@ -28,6 +28,8 @@
from swift.common.db import DatabaseBroker, DatabaseConnectionError, \
PENDING_CAP, PICKLE_PROTOCOL, utf8encode

DATADIR = 'containers'


class ContainerBroker(DatabaseBroker):
"""Encapsulates working with a container database."""
Expand Down
5 changes: 2 additions & 3 deletions swift/container/replicator.py
Original file line number Diff line number Diff line change
Expand Up @@ -13,15 +13,14 @@
# See the License for the specific language governing permissions and
# limitations under the License.

from swift.container import server as container_server
from swift.container.backend import ContainerBroker
from swift.container.backend import ContainerBroker, DATADIR
from swift.common import db_replicator


class ContainerReplicator(db_replicator.Replicator):
server_type = 'container'
brokerclass = ContainerBroker
datadir = container_server.DATADIR
datadir = DATADIR
default_port = 6001

def report_up_to_date(self, full_info):
Expand Down
4 changes: 1 addition & 3 deletions swift/container/server.py
Original file line number Diff line number Diff line change
Expand Up @@ -23,7 +23,7 @@
from eventlet import Timeout

import swift.common.db
from swift.container.backend import ContainerBroker
from swift.container.backend import ContainerBroker, DATADIR
from swift.common.db import DatabaseAlreadyExists
from swift.common.container_sync_realms import ContainerSyncRealms
from swift.common.request_helpers import get_param, get_listing_content_type, \
Expand All @@ -43,8 +43,6 @@
HTTPPreconditionFailed, HTTPMethodNotAllowed, Request, Response, \
HTTPInsufficientStorage, HTTPException, HeaderKeyDict

DATADIR = 'containers'


class ContainerController(object):
"""WSGI Controller for the container server."""
Expand Down
10 changes: 3 additions & 7 deletions swift/container/sync.py
Original file line number Diff line number Diff line change
Expand Up @@ -23,8 +23,7 @@
from eventlet import sleep, Timeout

import swift.common.db
from swift.container import server as container_server
from swift.container.backend import ContainerBroker
from swift.container.backend import ContainerBroker, DATADIR
from swift.common.container_sync_realms import ContainerSyncRealms
from swift.common.direct_client import direct_get_object
from swift.common.internal_client import delete_object, put_object
Expand Down Expand Up @@ -168,9 +167,7 @@ def run_forever(self, *args, **kwargs):
sleep(random() * self.interval)
while True:
begin = time()
all_locs = audit_location_generator(self.devices,
container_server.DATADIR,
'.db',
all_locs = audit_location_generator(self.devices, DATADIR, '.db',
mount_check=self.mount_check,
logger=self.logger)
for path, device, partition in all_locs:
Expand All @@ -187,8 +184,7 @@ def run_once(self, *args, **kwargs):
"""
self.logger.info(_('Begin container sync "once" mode'))
begin = time()
all_locs = audit_location_generator(self.devices,
container_server.DATADIR, '.db',
all_locs = audit_location_generator(self.devices, DATADIR, '.db',
mount_check=self.mount_check,
logger=self.logger)
for path, device, partition in all_locs:
Expand Down
3 changes: 1 addition & 2 deletions swift/container/updater.py
Original file line number Diff line number Diff line change
Expand Up @@ -25,8 +25,7 @@
from eventlet import spawn, patcher, Timeout

import swift.common.db
from swift.container.backend import ContainerBroker
from swift.container.server import DATADIR
from swift.container.backend import ContainerBroker, DATADIR
from swift.common.bufferedhttp import http_connect
from swift.common.exceptions import ConnectionTimeout
from swift.common.ring import Ring
Expand Down
2 changes: 1 addition & 1 deletion test/unit/account/test_reaper.py
Original file line number Diff line number Diff line change
Expand Up @@ -24,7 +24,7 @@
from contextlib import nested

from swift.account import reaper
from swift.account.server import DATADIR
from swift.account.backend import DATADIR
from swift.common.exceptions import ClientException
from swift.common.utils import normalize_timestamp

Expand Down
4 changes: 2 additions & 2 deletions test/unit/common/test_db_replicator.py
Original file line number Diff line number Diff line change
Expand Up @@ -26,9 +26,9 @@
import mock
import simplejson

from swift.container.backend import DATADIR
from swift.common import db_replicator
from swift.common.utils import normalize_timestamp
from swift.container import server as container_server
from swift.common.exceptions import DriveNotMounted
from swift.common.swob import HTTPException

Expand Down Expand Up @@ -247,7 +247,7 @@ class TestReplicator(db_replicator.Replicator):
server_type = 'container'
ring_file = 'container.ring.gz'
brokerclass = FakeBroker
datadir = container_server.DATADIR
datadir = DATADIR
default_port = 1000


Expand Down
7 changes: 3 additions & 4 deletions test/unit/container/test_updater.py
Original file line number Diff line number Diff line change
Expand Up @@ -25,8 +25,7 @@

from swift.common import utils
from swift.container import updater as container_updater
from swift.container import server as container_server
from swift.container.backend import ContainerBroker
from swift.container.backend import ContainerBroker, DATADIR
from swift.common.ring import RingData
from swift.common.utils import normalize_timestamp

Expand Down Expand Up @@ -84,7 +83,7 @@ def test_run_once(self):
'account_suppression_time': 0
})
cu.run_once()
containers_dir = os.path.join(self.sda1, container_server.DATADIR)
containers_dir = os.path.join(self.sda1, DATADIR)
os.mkdir(containers_dir)
cu.run_once()
self.assert_(os.path.exists(containers_dir))
Expand Down Expand Up @@ -167,7 +166,7 @@ def test_unicode(self):
'concurrency': '1',
'node_timeout': '15',
})
containers_dir = os.path.join(self.sda1, container_server.DATADIR)
containers_dir = os.path.join(self.sda1, DATADIR)
os.mkdir(containers_dir)
subdir = os.path.join(containers_dir, 'subdir')
os.mkdir(subdir)
Expand Down

0 comments on commit a7cfcc3

Please sign in to comment.