summaryrefslogtreecommitdiff
path: root/bin/swift-reconciler-enqueue
blob: 2a9dcc3a5552a02af4c51ecda4d72717279f5289 (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
#!/usr/bin/env python
# Licensed under the Apache License, Version 2.0 (the "License");
# you may not use this file except in compliance with the License.
# You may obtain a copy of the License at
#
#    http://www.apache.org/licenses/LICENSE-2.0
#
# Unless required by applicable law or agreed to in writing, software
# distributed under the License is distributed on an "AS IS" BASIS,
# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or
# implied.
# See the License for the specific language governing permissions and
# limitations under the License.
from __future__ import print_function
import sys
from optparse import OptionParser

import eventlet.debug
eventlet.debug.hub_exceptions(True)

from swift.common.ring import Ring
from swift.common.utils import split_path
from swift.common.storage_policy import POLICIES

from swift.container.reconciler import add_to_reconciler_queue
"""
This tool is primarily for debugging and development but can be used an example
of how an operator could enqueue objects manually if a problem is discovered -
might be particularly useful if you need to hack a fix into the reconciler
and re-run it.
"""

USAGE = """
%prog <policy_index> </a/c/o> <timestamp> [options]

This script enqueues an object to be evaluated by the reconciler.

Arguments:
policy_index: the policy the object is currently stored in.
      /a/c/o: the full path of the object - utf-8
   timestamp: the timestamp of the datafile/tombstone.

""".strip()

parser = OptionParser(USAGE)
parser.add_option('-X', '--op', default='PUT', choices=('PUT', 'DELETE'),
                  help='the method of the misplaced operation')
parser.add_option('-f', '--force', action='store_true',
                  help='force an object to be re-enqueued')


def main():
    options, args = parser.parse_args()
    try:
        policy_index, path, timestamp = args
    except ValueError:
        sys.exit(parser.print_help())
    container_ring = Ring('/etc/swift/container.ring.gz')
    policy = POLICIES.get_by_index(policy_index)
    if not policy:
        return 'ERROR: invalid storage policy index: %s' % policy
    try:
        account, container, obj = split_path(path, 3, 3, True)
    except ValueError as e:
        return 'ERROR: %s' % e
    container_name = add_to_reconciler_queue(
        container_ring, account, container, obj,
        policy.idx, timestamp, options.op, force=options.force)
    if not container_name:
        return 'ERROR: unable to enqueue!'
    print(container_name)


if __name__ == "__main__":
    sys.exit(main())