Skip to content

Commit

Permalink
Add rocksdb subcommand
Browse files Browse the repository at this point in the history
  • Loading branch information
fqqb committed May 24, 2024
1 parent c97dcc4 commit b86a98c
Show file tree
Hide file tree
Showing 7 changed files with 116 additions and 1 deletion.
7 changes: 7 additions & 0 deletions docs/conf.py
Original file line number Diff line number Diff line change
Expand Up @@ -203,6 +203,13 @@
author,
1,
),
(
"yamcs_rocksdb",
"yamcs-rocksdb",
"Manage RocksDB storage engine",
author,
1,
),
(
"yamcs_services",
"yamcs-services",
Expand Down
1 change: 1 addition & 0 deletions docs/index.rst
Original file line number Diff line number Diff line change
Expand Up @@ -39,6 +39,7 @@ Run :doc:`yamcs_login` to initialize your environment:
yamcs_parameter-archive
yamcs_parameters
yamcs_processors
yamcs_rocksdb
yamcs_services
yamcs_space-systems
yamcs_storage
Expand Down
2 changes: 2 additions & 0 deletions docs/yamcs.rst
Original file line number Diff line number Diff line change
Expand Up @@ -64,6 +64,8 @@ Commands
Manipulate the Parameter Archive. See :manpage:`yamcs-parameter-archive(1)`.
:doc:`processors <yamcs_processors>`
Manage processors. See :manpage:`yamcs-processors(1)`.
:doc:`rocksdb <yamcs_rocksdb>`
Manage RocksDB storage engine. See :manpage:`yamcs-rocksdb(1)`.
:doc:`services <yamcs_services>`
Read and manipulate services. See :manpage:`yamcs-services(1)`.
:doc:`space-systems <yamcs_space-systems>`
Expand Down
38 changes: 38 additions & 0 deletions docs/yamcs_rocksdb.rst
Original file line number Diff line number Diff line change
@@ -0,0 +1,38 @@
yamcs rocksdb
=============

.. program:: yamcs rocksdb

Synopsis
--------

.. rst-class:: synopsis

| **yamcs rocksdb** tablespaces
| **yamcs rocksdb** compact [--dbpath <*DBPATH*>] <*TABLESPACE*> <*CF*>

Description
-----------

Manage RocksDB storage engine.


Commands
--------

.. describe:: tablespaces

List processors

.. describe:: compact [--dbpath <DBPATH>] <TABLESPACE> <CF>

Delete a processor


Options
-------

.. option:: --dbpath <DBPATH>

With ``compact``, specify a path within the tablespace. Leave unspecified for the root database.
2 changes: 1 addition & 1 deletion setup.py
Original file line number Diff line number Diff line change
Expand Up @@ -36,7 +36,7 @@
"Operating System :: OS Independent",
],
platforms="Posix; MacOS X; Windows",
install_requires=["argcomplete", "python-dateutil", "yamcs-client>=1.9.5"],
install_requires=["argcomplete", "python-dateutil", "yamcs-client>=1.9.8"],
extras_require={"kerberos": ["yamcs-client-kerberos>=1.2.2"]},
include_package_data=True,
zip_safe=False,
Expand Down
2 changes: 2 additions & 0 deletions src/yamcs/cli/__main__.py
Original file line number Diff line number Diff line change
Expand Up @@ -24,6 +24,7 @@
from yamcs.cli.parameter_archive import ParameterArchiveCommand
from yamcs.cli.parameters import ParametersCommand
from yamcs.cli.processors import ProcessorsCommand
from yamcs.cli.rocksdb import RocksDBCommand
from yamcs.cli.services import ServicesCommand
from yamcs.cli.space_systems import SpaceSystemsCommand
from yamcs.cli.storage import StorageCommand
Expand Down Expand Up @@ -86,6 +87,7 @@ def main():
ParameterArchiveCommand(subparsers)
ParametersCommand(subparsers)
ProcessorsCommand(subparsers)
RocksDBCommand(subparsers)
ServicesCommand(subparsers)
SpaceSystemsCommand(subparsers)
StorageCommand(subparsers)
Expand Down
65 changes: 65 additions & 0 deletions src/yamcs/cli/rocksdb.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,65 @@
import sys
from typing import Any, List

from yamcs.client import YamcsClient

from yamcs.cli import utils


class RocksDBCommand(utils.Command):
def __init__(self, parent):
super(RocksDBCommand, self).__init__(
parent, "rocksdb", "Manage RocksDB storage engine"
)

subparsers = self.parser.add_subparsers(title="Commands", metavar="COMMAND")
subparsers.required = True

subparser = self.create_subparser(subparsers, "tablespaces", "List tablespaces")
subparser.set_defaults(func=self.tablespaces)

subparser = self.create_subparser(
subparsers, "compact", "Compact column family"
)
subparser.set_defaults(func=self.compact)
subparser.add_argument(
"tablespace",
metavar="TABLESPACE",
type=str,
help="RocksDB tablespace",
)
subparser.add_argument(
"cf",
metavar="CF",
type=str,
help="RocksDB column family",
)
subparser.add_argument(
"--dbpath",
metavar="PATH",
type=str,
help="Path within the tablespace",
)

def tablespaces(self, args):
opts = utils.CommandOptions(args)
client = YamcsClient(**opts.client_kwargs)

rows: List[List[Any]] = [["NAME", "DATA DIR"]]
for tablespace in client.list_rdb_tablespaces():
rows.append([tablespace.name, tablespace.data_dir])
utils.print_table(rows)

def compact(self, args):
opts = utils.CommandOptions(args)
client = YamcsClient(**opts.client_kwargs)

sys.stderr.write("Compacting... ")
sys.stderr.flush()
client.compact_rdb_column_family(
tablespace=args.tablespace,
cf=args.cf,
dbpath=args.dbpath or "",
)
sys.stderr.write("done\n")
sys.stderr.flush()

0 comments on commit b86a98c

Please sign in to comment.