mirror of
https://gitee.com/milvus-io/milvus.git
synced 2024-12-02 03:48:37 +08:00
Update Group handle
Former-commit-id: 763ec1587990a4c47ee52e1e255ca75e1b91320a
This commit is contained in:
parent
c40c217259
commit
095fccd4a5
@ -27,8 +27,14 @@ class MetaManager(object):
|
|||||||
else:
|
else:
|
||||||
return ErrorCode.FAULT_CODE, None
|
return ErrorCode.FAULT_CODE, None
|
||||||
|
|
||||||
# def DeleteGroup(group_id):
|
@staticmethod
|
||||||
# group = GroupTable.query.filter(GroupTable.group_name==group_id).first()
|
def DeleteGroup(group):
|
||||||
# if(group):
|
db.session.delete(group)
|
||||||
# db.session.delete(group)
|
|
||||||
# else:
|
@staticmethod
|
||||||
|
def DeleteGroupFiles(group_name):
|
||||||
|
records = FileTable.query.filter(FileTable.group_name == group_name).all()
|
||||||
|
for record in records:
|
||||||
|
print("record.group_name: ", record.group_name)
|
||||||
|
db.session.delete(record)
|
||||||
|
|
@ -14,6 +14,14 @@ class StorageManager(object):
|
|||||||
def GetGroupDirectory(group_name):
|
def GetGroupDirectory(group_name):
|
||||||
return DATABASE_DIRECTORY + '/' + group_name
|
return DATABASE_DIRECTORY + '/' + group_name
|
||||||
|
|
||||||
|
@staticmethod
|
||||||
|
def DeleteGroup(group_id):
|
||||||
|
path = StorageManager.GetGroupDirectory(group_id)
|
||||||
|
path = path.strip()
|
||||||
|
path=path.rstrip("\\")
|
||||||
|
if os.path.exists(path):
|
||||||
|
shutil.rmtree(path)
|
||||||
|
|
||||||
def Read():
|
def Read():
|
||||||
pass
|
pass
|
||||||
|
|
||||||
|
@ -21,10 +21,9 @@ class TestVectorEngine:
|
|||||||
|
|
||||||
def test_group(self):
|
def test_group(self):
|
||||||
# Make sure there is no group
|
# Make sure there is no group
|
||||||
code, group_id, file_number = VectorEngine.DeleteGroup('test_group')
|
code, group_id = VectorEngine.DeleteGroup('test_group')
|
||||||
assert code == VectorEngine.SUCCESS_CODE
|
assert code == VectorEngine.SUCCESS_CODE
|
||||||
assert group_id == 'test_group'
|
assert group_id == 'test_group'
|
||||||
assert file_number == 0
|
|
||||||
|
|
||||||
# Add a group
|
# Add a group
|
||||||
code, group_id = VectorEngine.AddGroup('test_group', 8)
|
code, group_id = VectorEngine.AddGroup('test_group', 8)
|
||||||
@ -32,10 +31,9 @@ class TestVectorEngine:
|
|||||||
assert group_id == 'test_group'
|
assert group_id == 'test_group'
|
||||||
|
|
||||||
# Check the group existing
|
# Check the group existing
|
||||||
code, group_id, file_number = VectorEngine.GetGroup('test_group')
|
code, group_id = VectorEngine.GetGroup('test_group')
|
||||||
assert code == VectorEngine.SUCCESS_CODE
|
assert code == VectorEngine.SUCCESS_CODE
|
||||||
assert group_id == 'test_group'
|
assert group_id == 'test_group'
|
||||||
assert file_number == 0
|
|
||||||
|
|
||||||
# Check the group list
|
# Check the group list
|
||||||
code, group_list = VectorEngine.GetGroupList()
|
code, group_list = VectorEngine.GetGroupList()
|
||||||
@ -63,16 +61,14 @@ class TestVectorEngine:
|
|||||||
assert code == VectorEngine.SUCCESS_CODE
|
assert code == VectorEngine.SUCCESS_CODE
|
||||||
|
|
||||||
# Remove the group
|
# Remove the group
|
||||||
code, group_id, file_number = VectorEngine.DeleteGroup('test_group')
|
code, group_id = VectorEngine.DeleteGroup('test_group')
|
||||||
assert code == VectorEngine.SUCCESS_CODE
|
assert code == VectorEngine.SUCCESS_CODE
|
||||||
assert group_id == 'test_group'
|
assert group_id == 'test_group'
|
||||||
assert file_number == 0
|
|
||||||
|
|
||||||
# Check the group is disppeared
|
# Check the group is disppeared
|
||||||
code, group_id, file_number = VectorEngine.GetGroup('test_group')
|
code, group_id = VectorEngine.GetGroup('test_group')
|
||||||
assert code == VectorEngine.FAULT_CODE
|
assert code == VectorEngine.FAULT_CODE
|
||||||
assert group_id == 'test_group'
|
assert group_id == 'test_group'
|
||||||
assert file_number == 0
|
|
||||||
|
|
||||||
# Check SearchVector interface
|
# Check SearchVector interface
|
||||||
code, vector_ids = VectorEngine.SearchVector('test_group', self.__vector, self.__limit)
|
code, vector_ids = VectorEngine.SearchVector('test_group', self.__vector, self.__limit)
|
||||||
|
@ -24,41 +24,35 @@ class VectorEngine(object):
|
|||||||
@staticmethod
|
@staticmethod
|
||||||
def AddGroup(group_name, dimension):
|
def AddGroup(group_name, dimension):
|
||||||
error, group = MetaManager.GetGroup(group_name)
|
error, group = MetaManager.GetGroup(group_name)
|
||||||
if(error == ErrorCode.SUCCESS_CODE):
|
if error == ErrorCode.SUCCESS_CODE:
|
||||||
return ErrorCode.FAULT_CODE, group_name
|
return ErrorCode.FAULT_CODE, group_name
|
||||||
else:
|
else:
|
||||||
StorageManager.AddGroup(group_name)
|
StorageManager.AddGroup(group_name)
|
||||||
MetaManager.AddGroup(group_name, dimension)
|
MetaManager.AddGroup(group_name, dimension)
|
||||||
return VectorEngine.SUCCESS_CODE, group_name
|
return ErrorCode.SUCCESS_CODE, group_name
|
||||||
|
|
||||||
|
|
||||||
@staticmethod
|
@staticmethod
|
||||||
def GetGroup(group_id):
|
def GetGroup(group_name):
|
||||||
group = GroupTable.query.filter(GroupTable.group_name==group_id).first()
|
error, _ = MetaManager.GetGroup(group_name)
|
||||||
if group:
|
return error, group_name
|
||||||
return VectorEngine.SUCCESS_CODE, group_id, group.file_number
|
|
||||||
else:
|
|
||||||
return VectorEngine.FAULT_CODE, group_id, 0
|
|
||||||
|
|
||||||
|
|
||||||
@staticmethod
|
@staticmethod
|
||||||
def DeleteGroup(group_id):
|
def DeleteGroup(group_name):
|
||||||
group = GroupTable.query.filter(GroupTable.group_name==group_id).first()
|
group = GroupTable.query.filter(GroupTable.group_name==group_name).first()
|
||||||
if(group):
|
if(group):
|
||||||
# old_group = GroupTable(group_id)
|
MetaManager.DeleteGroup(group)
|
||||||
db.session.delete(group)
|
StorageManager.DeleteGroup(group_name)
|
||||||
db.session.commit()
|
|
||||||
GroupHandler.DeleteGroupDirectory(group_id)
|
|
||||||
|
|
||||||
records = FileTable.query.filter(FileTable.group_name == group_id).all()
|
records = FileTable.query.filter(FileTable.group_name == group_name).all()
|
||||||
for record in records:
|
for record in records:
|
||||||
print("record.group_name: ", record.group_name)
|
print("record.group_name: ", record.group_name)
|
||||||
db.session.delete(record)
|
db.session.delete(record)
|
||||||
db.session.commit()
|
db.session.commit()
|
||||||
|
|
||||||
return VectorEngine.SUCCESS_CODE, group_id, group.file_number
|
return VectorEngine.SUCCESS_CODE, group_name
|
||||||
else:
|
else:
|
||||||
return VectorEngine.SUCCESS_CODE, group_id, 0
|
return VectorEngine.SUCCESS_CODE, group_name
|
||||||
|
|
||||||
|
|
||||||
@staticmethod
|
@staticmethod
|
||||||
@ -78,7 +72,7 @@ class VectorEngine(object):
|
|||||||
@staticmethod
|
@staticmethod
|
||||||
def AddVector(group_id, vectors):
|
def AddVector(group_id, vectors):
|
||||||
print(group_id, vectors)
|
print(group_id, vectors)
|
||||||
code, _, _ = VectorEngine.GetGroup(group_id)
|
code, _, = VectorEngine.GetGroup(group_id)
|
||||||
if code == VectorEngine.FAULT_CODE:
|
if code == VectorEngine.FAULT_CODE:
|
||||||
return VectorEngine.GROUP_NOT_EXIST, 'invalid'
|
return VectorEngine.GROUP_NOT_EXIST, 'invalid'
|
||||||
|
|
||||||
@ -140,7 +134,7 @@ class VectorEngine(object):
|
|||||||
@staticmethod
|
@staticmethod
|
||||||
def SearchVector(group_id, vector, limit):
|
def SearchVector(group_id, vector, limit):
|
||||||
# Check the group exist
|
# Check the group exist
|
||||||
code, _, _ = VectorEngine.GetGroup(group_id)
|
code, _ = VectorEngine.GetGroup(group_id)
|
||||||
if code == VectorEngine.FAULT_CODE:
|
if code == VectorEngine.FAULT_CODE:
|
||||||
return VectorEngine.GROUP_NOT_EXIST, {}
|
return VectorEngine.GROUP_NOT_EXIST, {}
|
||||||
|
|
||||||
@ -168,7 +162,7 @@ class VectorEngine(object):
|
|||||||
@staticmethod
|
@staticmethod
|
||||||
def CreateIndex(group_id):
|
def CreateIndex(group_id):
|
||||||
# Check the group exist
|
# Check the group exist
|
||||||
code, _, _ = VectorEngine.GetGroup(group_id)
|
code, _ = VectorEngine.GetGroup(group_id)
|
||||||
if code == VectorEngine.FAULT_CODE:
|
if code == VectorEngine.FAULT_CODE:
|
||||||
return VectorEngine.GROUP_NOT_EXIST
|
return VectorEngine.GROUP_NOT_EXIST
|
||||||
|
|
||||||
|
@ -63,11 +63,11 @@ class Group(Resource):
|
|||||||
return jsonify({'code': code, 'group': group_id, 'filenumber': 0})
|
return jsonify({'code': code, 'group': group_id, 'filenumber': 0})
|
||||||
|
|
||||||
def get(self, group_id):
|
def get(self, group_id):
|
||||||
code, group_id, file_number = VectorEngine.GetGroup(group_id)
|
code, group_id = VectorEngine.GetGroup(group_id)
|
||||||
return jsonify({'code': code, 'group': group_id, 'filenumber': 0})
|
return jsonify({'code': code, 'group': group_id, 'filenumber': 0})
|
||||||
|
|
||||||
def delete(self, group_id):
|
def delete(self, group_id):
|
||||||
code, group_id, file_number = VectorEngine.DeleteGroup(group_id)
|
code, group_id = VectorEngine.DeleteGroup(group_id)
|
||||||
return jsonify({'code': code, 'group': group_id, 'filenumber': 0})
|
return jsonify({'code': code, 'group': group_id, 'filenumber': 0})
|
||||||
|
|
||||||
|
|
||||||
|
Loading…
Reference in New Issue
Block a user