Exemplo n.º 1
0
def deleteFile(setting, metadata):
    '''Workflow of Delete file.'''
    if setting.deduplication == False:
        #Acquire write lock if using ZooKeeper:
        #if setting.zookeeper: setting.zk.getWriteLock(metadata) #cq
        #Download metadata:
        storage.downloadMetadata(setting, metadata)
        #Delete chunk files and metadata:
        storage.deleteChunkAndMetadata(setting, metadata)
        #Release write lock:
        #if setting.zookeeper: setting.zk.releaseWriteLock(metadata) #cq
    else:
        orgState = storage.detectOrgState(setting, metadata)
        if orgState == 3:
            # non_dup
            print "remove non_dup"      
            #Download metadata:
            storage.downloadMetadata(setting, metadata)
            #Delete chunk files and metadata:
            storage.deleteChunkAndMetadata(setting, metadata)
        elif orgState == 2:
            # leaf
            print "remove leaf"
            storage.deletePointer(setting, metadata)
        elif orgState == 1:
            # org
            print "remove org"
            storage.downloadMetadata(setting, metadata)
            storage.deleteChunkAndMetadata(setting, metadata)
            dupFileName = storage.findOnePointer(setting, metadata)
            dupMetadata = common.FileMetadata(dupFileName, 0, setting.totalnode, setting.coding)
            storage.deletePointer(setting, dupMetadata)
            coding.encodeFile(setting,dupMetadata)
            storage.uploadFileAndMetadata(setting, dupMetadata,'upload')
            storage.updatePointers(setting,metadata,dupMetadata)
Exemplo n.º 2
0
def deleteFile(setting, metadata):
    '''Workflow of Delete file.'''
    if setting.deduplication == False:
        #Acquire write lock if using ZooKeeper:
        #if setting.zookeeper: setting.zk.getWriteLock(metadata) #cq
        #Download metadata:
        storage.downloadMetadata(setting, metadata)
        #Delete chunk files and metadata:
        storage.deleteChunkAndMetadata(setting, metadata)
        #Release write lock:
        #if setting.zookeeper: setting.zk.releaseWriteLock(metadata) #cq
    else:
        orgState = storage.detectOrgState(setting, metadata)
        if orgState == 3:
            # non_dup
            print "remove non_dup"
            #Download metadata:
            storage.downloadMetadata(setting, metadata)
            #Delete chunk files and metadata:
            storage.deleteChunkAndMetadata(setting, metadata)
        elif orgState == 2:
            # leaf
            print "remove leaf"
            storage.deletePointer(setting, metadata)
        elif orgState == 1:
            # org
            print "remove org"
            storage.downloadMetadata(setting, metadata)
            storage.deleteChunkAndMetadata(setting, metadata)
            dupFileName = storage.findOnePointer(setting, metadata)
            dupMetadata = common.FileMetadata(dupFileName, 0,
                                              setting.totalnode,
                                              setting.coding)
            storage.deletePointer(setting, dupMetadata)
            coding.encodeFile(setting, dupMetadata)
            storage.uploadFileAndMetadata(setting, dupMetadata, 'upload')
            storage.updatePointers(setting, metadata, dupMetadata)
Exemplo n.º 3
0
def uploadFile(setting, metadata):
    '''Workflow of Upload file.'''
    if setting.deduplication == False:
        #Encode file:
        print "deduplication False, workflow upload file"        
        coding.encodeFile(setting, metadata)
        #Acquire write lock if using ZooKeeper:
        #if setting.zookeeper: setting.zk.getWriteLock(metadata) #cq
        #Upload chunk files and metadata:
        storage.uploadFileAndMetadata(setting, metadata, 'upload')
        #Release write lock:
        #if setting.zookeeper: setting.zk.releaseWriteLock(metadata) #cq
    else:
        print "deduplicatoin True, workflow upload file"
        orgState = storage.detectOrgState(setting, metadata)
        print "orgState %d" % (orgState)
        currState = storage.detectCurrState(setting, metadata)
        print "currState %d" % (currState[0])
        if orgState == 3 and currState[0] == 0:
            # non_dup => non_dup    or       new => non_dup
            print 'orgState %d to currState %d' % (orgState, currState[0])
            coding.encodeFile(setting, metadata)
            storage.uploadFileAndMetadata(setting,metadata,'upload')
        elif orgState == 3 and currState[0] == 1:
            # non_dup => leaf       or    new => leaf
            print 'orgState %d to currState %d' % (orgState, currState[0])
            detState = storage.detectReplica(setting, metadata)
            if detState == True:
                deleteFile(setting, metadata)            
            storage.createPointer(setting, metadata, currState[1])
            storage.uploadPointer(setting, metadata)
        elif orgState == 2 and currState[0] == 1:
            # leaf => leaf
            print 'orgState %d to currState %d' % (orgState, currState[0])
            storage.deletePointer(setting,metadata)
            storage.createPointer(setting,metadata,currState[1])
            storage.uploadPointer(setting,metadata)
        elif orgState == 2 and currState[0] == 0:
            # leaf => non_dup
            print 'orgState %d to currState %d' % (orgState, currState[0])
            storage.deletePointer(setting,metadata)
            coding.encodeFile(setting,metadata)
            storage.uploadFileAndMetadata(setting,metadata,'upload')
        elif orgState == 1 and currState[0] == 0:
            # org => non_dup
            print 'orgState %d to currState %d' % (orgState, currState[0])
            coding.encodeFile(setting,metadata)
            storage.uploadFileAndMetadata(setting,metadata,'upload')
            dupFileName = storage.findOnePointer(setting,metadata)
            dupMetadata = common.FileMetadata(dupFileName,0,setting.totalnode,setting.coding)
            storage.deletePointer(setting,dupMetadata)
            coding.encodeFile(setting,dupMetadata)
            storage.uploadFileAndMetadata(setting,dupMetadata,'upload')
            storage.updatePointers(setting,metadata,dupMetadata)
        elif orgState == 1 and currState[0] == 1:
            # org => leaf
            print 'orgState %d to currState %d' % (orgState, currState[0])
            deleteFile(setting,metadata)
            storage.createPointer(setting,metadata,currState[1])
            storage.uploadPointer(setting,metadata)
            '''
Exemplo n.º 4
0
def uploadFile(setting, metadata):
    '''Workflow of Upload file.'''
    if setting.deduplication == False:
        #Encode file:
        print "deduplication False, workflow upload file"
        coding.encodeFile(setting, metadata)
        #Acquire write lock if using ZooKeeper:
        #if setting.zookeeper: setting.zk.getWriteLock(metadata) #cq
        #Upload chunk files and metadata:
        storage.uploadFileAndMetadata(setting, metadata, 'upload')
        #Release write lock:
        #if setting.zookeeper: setting.zk.releaseWriteLock(metadata) #cq
    else:
        print "deduplicatoin True, workflow upload file"
        orgState = storage.detectOrgState(setting, metadata)
        print "orgState %d" % (orgState)
        currState = storage.detectCurrState(setting, metadata)
        print "currState %d" % (currState[0])
        if orgState == 3 and currState[0] == 0:
            # non_dup => non_dup    or       new => non_dup
            print 'orgState %d to currState %d' % (orgState, currState[0])
            coding.encodeFile(setting, metadata)
            storage.uploadFileAndMetadata(setting, metadata, 'upload')
        elif orgState == 3 and currState[0] == 1:
            # non_dup => leaf       or    new => leaf
            print 'orgState %d to currState %d' % (orgState, currState[0])
            detState = storage.detectReplica(setting, metadata)
            if detState == True:
                deleteFile(setting, metadata)
            storage.createPointer(setting, metadata, currState[1])
            storage.uploadPointer(setting, metadata)
        elif orgState == 2 and currState[0] == 1:
            # leaf => leaf
            print 'orgState %d to currState %d' % (orgState, currState[0])
            storage.deletePointer(setting, metadata)
            storage.createPointer(setting, metadata, currState[1])
            storage.uploadPointer(setting, metadata)
        elif orgState == 2 and currState[0] == 0:
            # leaf => non_dup
            print 'orgState %d to currState %d' % (orgState, currState[0])
            storage.deletePointer(setting, metadata)
            coding.encodeFile(setting, metadata)
            storage.uploadFileAndMetadata(setting, metadata, 'upload')
        elif orgState == 1 and currState[0] == 0:
            # org => non_dup
            print 'orgState %d to currState %d' % (orgState, currState[0])
            coding.encodeFile(setting, metadata)
            storage.uploadFileAndMetadata(setting, metadata, 'upload')
            dupFileName = storage.findOnePointer(setting, metadata)
            dupMetadata = common.FileMetadata(dupFileName, 0,
                                              setting.totalnode,
                                              setting.coding)
            storage.deletePointer(setting, dupMetadata)
            coding.encodeFile(setting, dupMetadata)
            storage.uploadFileAndMetadata(setting, dupMetadata, 'upload')
            storage.updatePointers(setting, metadata, dupMetadata)
        elif orgState == 1 and currState[0] == 1:
            # org => leaf
            print 'orgState %d to currState %d' % (orgState, currState[0])
            deleteFile(setting, metadata)
            storage.createPointer(setting, metadata, currState[1])
            storage.uploadPointer(setting, metadata)
            '''