11import datetime
22import functools
33import os
4+ import urllib .parse
45from typing import Any , Callable , Iterable , Iterator , List , Mapping , Optional , Union
56from urllib .parse import urlparse
67
2829 LinkEvent ,
2930 LoadParameterValuesResult ,
3031 Processor ,
32+ RdbTablespace ,
3133 ServerInfo ,
3234 Service ,
3335 UserInfo ,
3436)
37+ from yamcs .protobuf .archive import rocksdb_service_pb2
3538from yamcs .protobuf .auth import auth_pb2
3639from yamcs .protobuf .events import events_pb2 , events_service_pb2
3740from yamcs .protobuf .iam import iam_pb2
@@ -520,6 +523,38 @@ def list_links(self, instance: str) -> Iterable[Link]:
520523 links = getattr (message , "links" )
521524 return iter ([Link (link ) for link in links ])
522525
526+ def list_rdb_tablespaces (self ) -> Iterable [RdbTablespace ]:
527+ """
528+ Lists RocksDB tablespaces.
529+ """
530+ response = self .ctx .get_proto (path = "/archive/rocksdb/tablespaces" )
531+ message = rocksdb_service_pb2 .ListRocksDbTablespacesResponse ()
532+ message .ParseFromString (response .content )
533+ tablespaces = getattr (message , "tablespaces" )
534+ return iter ([RdbTablespace (tablespace ) for tablespace in tablespaces ])
535+
536+ def compact_rdb_column_family (
537+ self ,
538+ tablespace : str ,
539+ cf : str ,
540+ dbpath : Optional [str ] = None ,
541+ ):
542+ """
543+ Compact a RocksDB column family.
544+
545+ :param tablespace:
546+ RocksDB tablespace name
547+ :cf:
548+ Column family name
549+ :param dbpath:
550+ Optional path under the tablespace root.
551+ """
552+ req = rocksdb_service_pb2 .CompactDatabaseRequest ()
553+ req .cfname = cf
554+ encoded_name = urllib .parse .quote_plus (dbpath or "" )
555+ url = f"/archive/rocksdb/{ tablespace } /{ encoded_name } :compact"
556+ self .ctx .post_proto (url , data = req .SerializeToString ())
557+
523558 def send_event (
524559 self ,
525560 instance : str ,
@@ -540,7 +575,6 @@ def send_event(
540575 Event message.
541576 :param event_type:
542577 Type of event.
543-
544578 :param severity:
545579 The severity level of the event. One of ``info``,
546580 ``watch``, ``warning``, ``distress``, ``critical``
0 commit comments