Skip to content

Commit ee85488

Browse files
committed
Add compact operation
1 parent 32ba1f7 commit ee85488

2 files changed

Lines changed: 50 additions & 1 deletion

File tree

yamcs-client/src/yamcs/client/core.py

Lines changed: 35 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,7 @@
11
import datetime
22
import functools
33
import os
4+
import urllib.parse
45
from typing import Any, Callable, Iterable, Iterator, List, Mapping, Optional, Union
56
from urllib.parse import urlparse
67

@@ -28,10 +29,12 @@
2829
LinkEvent,
2930
LoadParameterValuesResult,
3031
Processor,
32+
RdbTablespace,
3133
ServerInfo,
3234
Service,
3335
UserInfo,
3436
)
37+
from yamcs.protobuf.archive import rocksdb_service_pb2
3538
from yamcs.protobuf.auth import auth_pb2
3639
from yamcs.protobuf.events import events_pb2, events_service_pb2
3740
from 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``

yamcs-client/src/yamcs/model.py

Lines changed: 15 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -297,6 +297,21 @@ def checked(self) -> bool:
297297
return self._proto.checked
298298

299299

300+
class RdbTablespace:
301+
def __init__(self, proto):
302+
self._proto = proto
303+
304+
@property
305+
def name(self) -> str:
306+
"""Tablespace name"""
307+
return self._proto.name
308+
309+
@property
310+
def data_dir(self) -> str:
311+
"""Data directory"""
312+
return self._proto.dataDir
313+
314+
300315
class Instance:
301316
def __init__(self, proto):
302317
self._proto = proto

0 commit comments

Comments
 (0)