Skip to content

Commit

Permalink
CA-196882: FileSR and GC changes
Browse files Browse the repository at this point in the history
FileSR performs VDI.delete inline
GC waits five minutes after start before initiating work loop.
Use two locks in gcLoop, one to prevent multiple GC processs starting
and one to interlink with abort requests while work is actually occuring.

Signed-off-by: Mark Syms <mark.syms@citrix.com>
  • Loading branch information
MarkSymsCtx committed Feb 1, 2016
1 parent 4eee7cf commit 9decdde
Showing 1 changed file with 40 additions and 26 deletions.
66 changes: 40 additions & 26 deletions drivers/cleanup.py
Original file line number Diff line number Diff line change
Expand Up @@ -62,6 +62,11 @@
LOCK_TYPE_RUNNING = "running"
lockRunning = None

# process "lock" to indicate that the GC process has been activated but may not
# yet be running, stops a second process from being started.
LOCK_TYPE_GC_ACTIVE = "gc_active"
lockActive = None

# Default coalesce error rate limit, in messages per minute. A zero value
# disables throttling, and a negative value disables error reporting.
DEFAULT_COALESCE_ERR_RATE = 1.0/60
Expand Down Expand Up @@ -2532,8 +2537,8 @@ def normalizeType(type):
return type

def _gcLoop(sr, dryRun):
if not lockRunning.acquireNoblock():
Util.log("Another instance already running, exiting")
if not lockActive.acquireNoblock():
Util.log("Another GC instance already active, exiting")
return
try:
# TODO: make the delay configurable
Expand All @@ -2550,34 +2555,40 @@ def _gcLoop(sr, dryRun):
Util.log("No work, exiting")
break

if not sr.gcEnabled():
break
sr.cleanupCoalesceJournals()
sr.scanLocked()
sr.updateBlockInfo()
if not lockRunning.acquireNoblock():
Util.log("Unable to acquire GC running lock.")
return
try:
if not sr.gcEnabled():
break
sr.cleanupCoalesceJournals()
sr.scanLocked()
sr.updateBlockInfo()

if len(sr.findGarbage()) > 0:
sr.garbageCollect(dryRun)
sr.xapi.srUpdate()
continue
if len(sr.findGarbage()) > 0:
sr.garbageCollect(dryRun)
sr.xapi.srUpdate()
continue

candidate = sr.findCoalesceable()
if candidate:
util.fistpoint.activate("LVHDRT_finding_a_suitable_pair",sr.uuid)
sr.coalesce(candidate, dryRun)
sr.xapi.srUpdate()
continue
candidate = sr.findCoalesceable()
if candidate:
util.fistpoint.activate("LVHDRT_finding_a_suitable_pair",sr.uuid)
sr.coalesce(candidate, dryRun)
sr.xapi.srUpdate()
continue

candidate = sr.findLeafCoalesceable()
if candidate:
sr.coalesceLeaf(candidate, dryRun)
sr.xapi.srUpdate()
continue
candidate = sr.findLeafCoalesceable()
if candidate:
sr.coalesceLeaf(candidate, dryRun)
sr.xapi.srUpdate()
continue

Util.log("No work left")
sr.cleanup()
Util.log("No work left")
sr.cleanup()
finally:
lockRunning.release()
finally:
lockRunning.release()
lockActive.release()

def _gc(session, srUuid, dryRun):
init(srUuid)
Expand Down Expand Up @@ -2625,7 +2636,10 @@ def _abort(srUuid, soft=False):
def init(srUuid):
global lockRunning
if not lockRunning:
lockRunning = lock.Lock(LOCK_TYPE_RUNNING, srUuid)
lockRunning = lock.Lock(LOCK_TYPE_RUNNING, srUuid)
global lockActive
if not lockActive:
lockActive = lock.Lock(LOCK_TYPE_GC_ACTIVE, srUuid)

def usage():
output = """Garbage collect and/or coalesce VHDs in a VHD-based SR
Expand Down

0 comments on commit 9decdde

Please sign in to comment.