Skip to content

Commit

Permalink
truncate send/receive task trails periodically. #886
Browse files Browse the repository at this point in the history
  • Loading branch information
schakrava committed Dec 10, 2015
1 parent 90848a5 commit ec15fc9
Show file tree
Hide file tree
Showing 2 changed files with 15 additions and 7 deletions.
12 changes: 10 additions & 2 deletions src/rockstor/smart_manager/replication/listener_broker.py
Original file line number Diff line number Diff line change
Expand Up @@ -20,8 +20,9 @@
import zmq
import os
import json
import time
from storageadmin.models import (NetworkInterface, Appliance)
from smart_manager.models import (ReplicaTrail, ReplicaShare, Replica)
from smart_manager.models import (ReplicaTrail, ReplicaShare, Replica, Service)
from django.conf import settings
from sender import Sender
from receiver import Receiver
Expand All @@ -40,6 +41,7 @@ def __init__(self):
self.remote_senders = {} # Active incoming/remote Sender/client map.
self.MAX_ATTEMPTS = settings.REPLICATION.get('max_send_attempts')
self.uuid = self.listener_interface = self.listener_port = None
self.trail_prune_time = None
super(ReplicaScheduler, self).__init__()

def _prune_workers(self, workers):
Expand Down Expand Up @@ -157,7 +159,6 @@ def _process_send(self, replica):
def run(self):
self.law = APIWrapper()
try:
from smart_manager.models import Service
so = Service.objects.get(name='replication')
config_d = json.loads(so.config)
self.listener_interface = NetworkInterface.objects.get(name=config_d['network_interface']).ipaddr
Expand Down Expand Up @@ -281,6 +282,13 @@ def run(self):
iterations = 10
self._prune_senders()
self._delete_receivers()
cur_time = time.time()
if (self.trail_prune_time is None or (cur_time - self.trail_prune_time) > 3600):
#prune send/receive trails every hour or so.
self.trail_prune_time = cur_time
map(self.prune_replica_trail, Replica.objects.filter())
map(self.prune_receive_trail, ReplicaShare.objects.filter())
logger.debug('Replica trails are truncated successfully.')

if (os.getppid() != self.ppid):
logger.error('Parent exited. Aborting.')
Expand Down
10 changes: 5 additions & 5 deletions src/rockstor/smart_manager/replication/util.py
Original file line number Diff line number Diff line change
Expand Up @@ -93,20 +93,20 @@ def update_receive_trail(self, rtid, data):
(url, e.__str__()))
raise Exception(msg)

def prune_trail(self, url, days=1):
def prune_trail(self, url, days=7):
try:
data = {'days': days, }
return self.law.api_call(url, data=data, calltype='delete', save_error=False)
except Exception, e:
msg = ('Exception while pruning trail for url(%s): %s' % (url, e.__str__()))
raise Exception(msg)

def prune_receive_trail(self, rid):
url = ('sm/replicas/rtrail/rshare/%d' % rid)
def prune_receive_trail(self, ro):
url = ('sm/replicas/rtrail/rshare/%d' % ro.id)
return self.prune_trail(url)

def prune_replica_trail(self, rid):
url = ('sm/replicas/trail/replica/%d' % rid)
def prune_replica_trail(self, ro):
url = ('sm/replicas/trail/replica/%d' % ro.id)
return self.prune_trail(url)

def create_snapshot(self, sname, snap_name, snap_type='replication'):
Expand Down

0 comments on commit ec15fc9

Please sign in to comment.