Skip to content

Commit

Permalink
fix metadata table structure (#330)
Browse files Browse the repository at this point in the history
  • Loading branch information
JoinTyang committed Jun 29, 2024
1 parent 91ef4f9 commit fe35425
Show file tree
Hide file tree
Showing 4 changed files with 119 additions and 114 deletions.
15 changes: 9 additions & 6 deletions repo_metadata/index_worker.py
Original file line number Diff line number Diff line change
Expand Up @@ -79,8 +79,8 @@ def worker_handler(self):
if len(msg) != 3:
logger.info('Bad message: %s' % str(msg))
else:
repo_id, commit_id = msg[1], msg[2]
self.worker_task_handler(self.mq, repo_id, commit_id, self.should_stop)
op_type, repo_id, commit_id = msg[0], msg[1], msg[2]
self.worker_task_handler(self.mq, repo_id, commit_id, op_type, self.should_stop)
except (ResponseError, NoMQAvailable, TimeoutError) as e:
logger.error('The connection to the redis server failed: %s' % e)
except Exception as e:
Expand All @@ -89,7 +89,7 @@ def worker_handler(self):
# prevent case that redis break at program running.
time.sleep(0.3)

def worker_task_handler(self, mq, repo_id, commit_id, should_stop):
def worker_task_handler(self, mq, repo_id, commit_id, op_type, should_stop):
# Python cannot kill threads, so stop it generate more locked key.
if not should_stop.isSet():
# set key-value if does not exist which will expire 30 minutes later
Expand All @@ -100,7 +100,7 @@ def worker_task_handler(self, mq, repo_id, commit_id, should_stop):
(threading.currentThread().getName(), repo_id))
lock_key = self._get_lock_key(repo_id)
self.locked_keys.add(lock_key)
self.update_metadata(repo_id)
self.update_metadata(repo_id, op_type)
try:
self.locked_keys.remove(lock_key)
except KeyError:
Expand All @@ -112,14 +112,17 @@ def worker_task_handler(self, mq, repo_id, commit_id, should_stop):
# the repo is updated by other thread, push back to the queue
self.add_to_undo_task(mq, repo_id, commit_id)

def update_metadata(self, repo_id):
def update_metadata(self, repo_id, op_type):
commit_id = repo_data.get_repo_head_commit(repo_id)
if not commit_id:
# invalid repo without head commit id
logger.error("invalid repo : %s " % repo_id)
return
try:
self.metadata_manager.update_metadata(repo_id, commit_id)
if op_type == 'init_metadata':
self.metadata_manager.create_metadata(repo_id)
else:
self.metadata_manager.update_metadata(repo_id, commit_id)
except Exception as e:
logger.exception('update repo: %s metadata error: %s', repo_id, e)

Expand Down
38 changes: 23 additions & 15 deletions repo_metadata/metadata_server_api.py
Original file line number Diff line number Diff line change
Expand Up @@ -3,35 +3,43 @@
from seafevents.app.config import METADATA_SERVER_SECRET_KEY, METADATA_SERVER_URL


class StructureTable(object):
def __init__(self, id, name):
self.id = id
class MetadataTable(object):
def __init__(self, table_id, name):
self.id = table_id
self.name = name

@property
def columns(self):
return MetadataColumns()

class StructureColumn(object):

class MetadataColumns(object):
def __init__(self):
self.id = MetadataColumn('_id', '_id', 'text')
self.file_creator = MetadataColumn('_file_creator', '_file_creator', 'text')
self.file_ctime = MetadataColumn('_file_ctime', '_file_ctime', 'date')
self.file_modifier = MetadataColumn('_file_modifier', '_file_modifier', 'text')
self.file_mtime = MetadataColumn('_file_mtime', '_file_mtime', 'date')
self.parent_dir = MetadataColumn('_parent_dir', '_parent_dir', 'text')
self.file_name = MetadataColumn('_name', '_name', 'text')
self.is_dir = MetadataColumn('_is_dir', '_is_dir', 'text')


class MetadataColumn(object):
def __init__(self, key, name, type):
self.key = key
self.name = name
self.type = type

def to_build_column_dict(self):
def to_dict(self):
return {
'key': self.key,
'name': self.name,
'type': self.type
}

#metadata base
METADATA_TABLE = StructureTable('0001', 'Table1')
METADATA_COLUMN_ID = StructureColumn('_id', '_id', 'text')
METADATA_COLUMN_CREATOR = StructureColumn('_file_creator', '_file_creator', 'text')
METADATA_COLUMN_CREATED_TIME = StructureColumn('_file_ctime', '_file_ctime', 'date')
METADATA_COLUMN_MODIFIER = StructureColumn('_file_modifier', '_file_modifier', 'text')
METADATA_COLUMN_MODIFIED_TIME = StructureColumn('_file_mtime', '_file_mtime', 'date')
METADATA_COLUMN_PARENT_DIR = StructureColumn('_parent_dir', '_parent_dir', 'text')
METADATA_COLUMN_NAME = StructureColumn('_name', '_name', 'text')
METADATA_COLUMN_IS_DIR = StructureColumn('_is_dir', '_is_dir', 'text')

METADATA_TABLE = MetadataTable('0001', 'Table1')


def parse_response(response):
Expand Down
Loading

0 comments on commit fe35425

Please sign in to comment.