Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Support purge operation in the gRPC server #448

Merged
merged 5 commits into from
May 12, 2022
Merged
Show file tree
Hide file tree
Changes from 4 commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
3 changes: 3 additions & 0 deletions medusa/config.py
Original file line number Diff line number Diff line change
Expand Up @@ -206,6 +206,9 @@ def parse_config(args, config_file):
if evaluate_boolean(config['cassandra']['use_sudo']):
logging.warning('Forcing use_sudo to False because Kubernetes mode is enabled')
config['cassandra']['use_sudo'] = 'False'
config['storage']['use_sudo_for_restore'] = 'False'
if "POD_IP" in os.environ:
config['storage']['fqdn'] = os.environ["POD_IP"]

resolve_ip_addresses = evaluate_boolean(config['cassandra']['resolve_ip_addresses'])
config.set('cassandra', 'resolve_ip_addresses', 'True' if resolve_ip_addresses else 'False')
Expand Down
13 changes: 5 additions & 8 deletions medusa/purge.py
Original file line number Diff line number Diff line change
Expand Up @@ -43,11 +43,13 @@ def main(config, max_backup_age=0, max_backup_count=0):
# list all backups to purge based on count conditions
backups_to_purge |= set(backups_to_purge_by_count(backups, max_backup_count))
# purge all candidate backups
purge_backups(storage, backups_to_purge, config.storage.backup_grace_period_in_days, config.storage.fqdn)
(nb_objects_purged, total_purged_size, total_objects_within_grace) \
= purge_backups(storage, backups_to_purge, config.storage.backup_grace_period_in_days, config.storage.fqdn)

logging.debug('Emitting metrics')
tags = ['medusa-node-backup', 'purge-error', 'PURGE-ERROR']
monitoring.send(tags, 0)
return (nb_objects_purged, total_purged_size, total_objects_within_grace, len(backups_to_purge))
except Exception as e:
traceback.print_exc()
tags = ['medusa-node-backup', 'purge-error', 'PURGE-ERROR']
Expand Down Expand Up @@ -75,13 +77,6 @@ def backups_to_purge_by_count(backups, max_backup_count):
return sorted_node_backups[:backups_to_remove_count]
return list()

# def backups_to_purge_by_name(backups, backup_name):
# """
# Return a list
# Returns the list of the backups to delete for a given name (1 name = 1 backup, but on N nodes).
# """
# return list(filter(lambda backup: backup.name = backup_name, backups)) or list()


def purge_backups(storage, backups, backup_grace_period_in_days, local_fqdn):
"""
Expand Down Expand Up @@ -122,6 +117,8 @@ def purge_backups(storage, backups, backup_grace_period_in_days, local_fqdn):
backup_grace_period_in_days
))

return (nb_objects_purged, total_purged_size, total_objects_within_grace)


def purge_backup(storage, backup):
purged_objects = 0
Expand Down
10 changes: 10 additions & 0 deletions medusa/service/grpc/client.py
Original file line number Diff line number Diff line change
Expand Up @@ -100,3 +100,13 @@ def backup_exists(self, name):
except grpc.RpcError as e:
logging.error("Failed to determine if backup exists for backup name: {} due to error: {}".format(name, e))
return False

def purge_backups(self):
try:
stub = medusa_pb2_grpc.MedusaStub(self.channel)
request = medusa_pb2.PurgeBackupsRequest()
resp = stub.PurgeBackups(request)
return resp
except grpc.RpcError as e:
logging.error("Failed to purge backupsdue to error: {}".format(e))
jeffbanks marked this conversation as resolved.
Show resolved Hide resolved
return None
13 changes: 13 additions & 0 deletions medusa/service/grpc/medusa.proto
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,8 @@ service Medusa {
rpc DeleteBackup(DeleteBackupRequest) returns (DeleteBackupResponse);

rpc GetBackups(GetBackupsRequest) returns (GetBackupsResponse);

rpc PurgeBackups(PurgeBackupsRequest) returns (PurgeBackupsResponse);
}

enum StatusType {
Expand Down Expand Up @@ -71,11 +73,22 @@ message BackupSummary {
int32 finishedNodes = 5;
repeated BackupNode nodes = 6;
StatusType status = 7;
string backupType = 8;
}

message BackupNode {
string host = 1;
repeated int64 tokens = 2;
string datacenter = 3;
string rack = 4;
}

message PurgeBackupsRequest {
jeffbanks marked this conversation as resolved.
Show resolved Hide resolved
}

message PurgeBackupsResponse {
int32 nbBackupsPurged = 1;
int32 nbObjectsPurged = 2;
int64 totalPurgedSize = 3;
int32 totalObjectsWithinGcGrace = 4;
jeffbanks marked this conversation as resolved.
Show resolved Hide resolved
}
Loading