# Path: biggraphite/metadata_cache.py
# METRICS_LABELS = ["type", "name"]
# CACHE_SIZE = prometheus_client.Gauge("bg_cache_size", "Current size", METRICS_LABELS)
# CACHE_MAX_SIZE = prometheus_client.Gauge("bg_cache_maxsize", "Max size", METRICS_LABELS)
# CACHE_HITS = prometheus_client.Counter(
#     "bg_cache_hits_total", "Cache hits", METRICS_LABELS
# )
# CACHE_MISSES = prometheus_client.Counter(
#     "bg_cache_misses_total", "Cache misses", METRICS_LABELS
# )
#     TYPE = "abstract"
#     TYPE = "memory"
#     TYPE = "disk"
#     __SINGLETONS = {}
#     __SINGLETONS_LOCK = threading.Lock()
#     _MAX_READERS = 2048
#     _METRIC_SEPARATOR = "|"
#     _EMPTY = b"nil"
#     MAP_SIZE = 1024 * 1024 * 1024 * 16 if sys.maxsize > 2 ** 32 else 1024 * 1024 * 1024
# class Error(Exception):
# class InvalidArgumentError(Error):
# class MetadataCache(object):
# class MemoryCache(MetadataCache):
# class DiskCache(MetadataCache):
# class NoneCache(MetadataCache):
#     def __init__(self, accessor, settings, name=None):
#     def open(self):
#     def __enter__(self):
#     def __exit__(self, typ, value, traceback):
#     def close(self):
#     def hit_count(self):
#     def miss_count(self):
#     def cache_has(self, metric_name):
#     def cache_drop(self, metric_name):
#     def cache_set(self, metric_name, metric):
#     def create_metric(self, metric, metric_name=None):
#     def has_metric(self, metric_name):
#     def get_metric(self, metric_name):
#     def clean(self):
#     def repair(
#         self,
#         start_key=None,
#         end_key=None,
#         shard=0,
#         nshards=1,
#         callback_on_progress=None,
#     ):
#     def metadata_from_str(self, metadata_str):
#     def _cache_has(self, metric_name):
#     def _cache_get(self, metric_name):
#     def _cache_set(self, metric_name, metric):
#     def stats(self):
#     def __init__(self, accessor, settings, name=None):
#     def open(self):
#         def _timer():
#     def close(self):
#     def _cache_has(self, metric_name):
#     def _cache_get(self, metric_name):
#     def _cache_set(self, metric_name, metric):
#     def _cache_drop(self, metric_name):
#     def clean(self):
#     def repair(
#         self,
#         start_key=None,
#         end_key=None,
#         shard=0,
#         nshards=1,
#         callback_on_progress=None,
#     ):
#     def _repair(self, start_key, end_key, shard, nshards, callback_on_progress):
#     def stats(self):
#     def __init__(self, accessor, settings, name=None):
#     def open(self):
#     def close(self):
#     def _cache_has(self, metric_name):
#     def __expired_timestamp(self, timestamp):
#     def _encode(self, value):
#     def _decode(self, value):
#     def _cache_get(self, metric_name):
#     def _cache_set(self, metric_name, metric):
#     def stats(self):
#     def __value_from_strings(self, metric_id, metric_metadata):
#     def __value_from_metric(self, metric):
#     def __split_payload(self, payload):
#     def clean(self):
#     def _clean_some(self, txn, cursor, cutoff):
#     def repair(
#         self,
#         start_key=None,
#         end_key=None,
#         shard=0,
#         nshards=1,
#         callback_on_progress=None,
#     ):
#     def __init__(self, accessor, settings, name=None):
#     def open(self):
#     def close(self):
#     def clean(self):
#     def repair(self, start_key=None, end_key=None, shard=0, nshards=1, callback_on_progress=None):
#     def _cache_has(self, metric_name):
#     def _cache_get(self, metric_name):
#     def _cache_set(self, metric_name, metric):
#     def stats(self):
# 
# Path: biggraphite/cli/command.py
# class BaseCommand(object):
# class ParseDateTimeArg(argparse.Action):
#     NAME = ""
#     HELP = ""
#     def add_arguments(self, parser):
#     def run(self, accessor, opts):
#     def __call__(self, parser, namespace, datetime_str, option_string=None):
# def date_time_from_str(datetime_str):
# def add_sharding_arguments(parser):
# def add_clean_arguments(parser):


import logging
import os
import sys
import progressbar
from prometheus_client import write_to_textfile, REGISTRY
from biggraphite import metadata_cache
from biggraphite.cli import command
        command.add_sharding_arguments(parser)
        parser.add_argument(
            "--quiet",
            action="store_const",
            default=False,
            const=True,
            help="Show no output unless there are problems.",
        )
        parser.add_argument(
            "--metrics-file-path",
            help="Dump metrics in file",
            type=str,
            default="",
            action="store"
        )

    def run(self, accessor, opts, on_progress=None):
        """Run some repairs.

        See command.BaseCommand
        """
        accessor.connect()

        # TODO: use multiprocessing + progressbar here. Probably remove some
        # of the current arguments and generate them instead based on a number
        # of processes to do a full scan.
        self.metrics_file_path = opts.metrics_file_path

        if opts.storage_dir:
            settings = {"path": opts.storage_dir}

# Path: biggraphite/metadata_cache.py
# METRICS_LABELS = ["type", "name"]
# CACHE_SIZE = prometheus_client.Gauge("bg_cache_size", "Current size", METRICS_LABELS)
# CACHE_MAX_SIZE = prometheus_client.Gauge("bg_cache_maxsize", "Max size", METRICS_LABELS)
# CACHE_HITS = prometheus_client.Counter(
#     "bg_cache_hits_total", "Cache hits", METRICS_LABELS
# )
# CACHE_MISSES = prometheus_client.Counter(
#     "bg_cache_misses_total", "Cache misses", METRICS_LABELS
# )
#     TYPE = "abstract"
#     TYPE = "memory"
#     TYPE = "disk"
#     __SINGLETONS = {}
#     __SINGLETONS_LOCK = threading.Lock()
#     _MAX_READERS = 2048
#     _METRIC_SEPARATOR = "|"
#     _EMPTY = b"nil"
#     MAP_SIZE = 1024 * 1024 * 1024 * 16 if sys.maxsize > 2 ** 32 else 1024 * 1024 * 1024
# class Error(Exception):
# class InvalidArgumentError(Error):
# class MetadataCache(object):
# class MemoryCache(MetadataCache):
# class DiskCache(MetadataCache):
# class NoneCache(MetadataCache):
#     def __init__(self, accessor, settings, name=None):
#     def open(self):
#     def __enter__(self):
#     def __exit__(self, typ, value, traceback):
#     def close(self):
#     def hit_count(self):
#     def miss_count(self):
#     def cache_has(self, metric_name):
#     def cache_drop(self, metric_name):
#     def cache_set(self, metric_name, metric):
#     def create_metric(self, metric, metric_name=None):
#     def has_metric(self, metric_name):
#     def get_metric(self, metric_name):
#     def clean(self):
#     def repair(
#         self,
#         start_key=None,
#         end_key=None,
#         shard=0,
#         nshards=1,
#         callback_on_progress=None,
#     ):
#     def metadata_from_str(self, metadata_str):
#     def _cache_has(self, metric_name):
#     def _cache_get(self, metric_name):
#     def _cache_set(self, metric_name, metric):
#     def stats(self):
#     def __init__(self, accessor, settings, name=None):
#     def open(self):
#         def _timer():
#     def close(self):
#     def _cache_has(self, metric_name):
#     def _cache_get(self, metric_name):
#     def _cache_set(self, metric_name, metric):
#     def _cache_drop(self, metric_name):
#     def clean(self):
#     def repair(
#         self,
#         start_key=None,
#         end_key=None,
#         shard=0,
#         nshards=1,
#         callback_on_progress=None,
#     ):
#     def _repair(self, start_key, end_key, shard, nshards, callback_on_progress):
#     def stats(self):
#     def __init__(self, accessor, settings, name=None):
#     def open(self):
#     def close(self):
#     def _cache_has(self, metric_name):
#     def __expired_timestamp(self, timestamp):
#     def _encode(self, value):
#     def _decode(self, value):
#     def _cache_get(self, metric_name):
#     def _cache_set(self, metric_name, metric):
#     def stats(self):
#     def __value_from_strings(self, metric_id, metric_metadata):
#     def __value_from_metric(self, metric):
#     def __split_payload(self, payload):
#     def clean(self):
#     def _clean_some(self, txn, cursor, cutoff):
#     def repair(
#         self,
#         start_key=None,
#         end_key=None,
#         shard=0,
#         nshards=1,
#         callback_on_progress=None,
#     ):
#     def __init__(self, accessor, settings, name=None):
#     def open(self):
#     def close(self):
#     def clean(self):
#     def repair(self, start_key=None, end_key=None, shard=0, nshards=1, callback_on_progress=None):
#     def _cache_has(self, metric_name):
#     def _cache_get(self, metric_name):
#     def _cache_set(self, metric_name, metric):
#     def stats(self):
# 
# Path: biggraphite/cli/command.py
# class BaseCommand(object):
# class ParseDateTimeArg(argparse.Action):
#     NAME = ""
#     HELP = ""
#     def add_arguments(self, parser):
#     def run(self, accessor, opts):
#     def __call__(self, parser, namespace, datetime_str, option_string=None):
# def date_time_from_str(datetime_str):
# def add_sharding_arguments(parser):
# def add_clean_arguments(parser):


# Path: biggraphite/cli/command_repair.py
import logging
import os
import sys
import progressbar
from prometheus_client import write_to_textfile, REGISTRY
from biggraphite import metadata_cache
from biggraphite.cli import command

        command.add_sharding_arguments(parser)
        parser.add_argument(
            "--quiet",
            action="store_const",
            default=False,
            const=True,
            help="Show no output unless there are problems.",
        )
        parser.add_argument(
            "--metrics-file-path",
            help="Dump metrics in file",
            type=str,
            default="",
            action="store"
        )

    def run(self, accessor, opts, on_progress=None):
        """Run some repairs.

        See command.BaseCommand
        """
        accessor.connect()

        # TODO: use multiprocessing + progressbar here. Probably remove some
        # of the current arguments and generate them instead based on a number
        # of processes to do a full scan.
        self.metrics_file_path = opts.metrics_file_path

        if opts.storage_dir:
            settings = {"path": opts.storage_dir}

            with metadata_cache.DiskCache(accessor, settings) as cache: