栏目分类:
子分类:
返回
名师互学网用户登录
快速导航关闭
当前搜索
当前分类
子分类
实用工具
热门搜索
名师互学网 > IT > 前沿技术 > 大数据 > 大数据系统

【山大智云项目日志】Seahub+Proset分析(12)

【山大智云项目日志】Seahub+Proset分析(12)

2021SC@SDUSC

之前我们分析了seafes部分的文件,这一次我们继续分析。

Seafes index

之前我们已经知道index文件夹中包含索引所需要的的一些基础类和函数。现在我们来深入分析这部分的代码。

base.py

base.py文件主要包含了ES中索引的基类。提供一些辅助函数,如create_index_if_missing()和refresh()。

def create_index_if_missing(self, index_settings=None):
        if not self.es.indices.exists(index=self.INDEX_NAME):
            body = {}
            if index_settings:
                body['settings'] = index_settings
            self.es.indices.create(index=self.INDEX_NAME, body=body)

            self.es.indices.put_mapping(
                index=self.INDEX_NAME,
                doc_type=self.MAPPING_TYPE,
                body=self.MAPPING
            )

            self.es.indices.refresh(index=self.INDEX_NAME)

如果缺失索引,则create_index_if_missing函数可以创建索引。 

 def refresh(self):
        self.es.indices.refresh(index=self.INDEX_NAME)

refresh函数用于刷新索引。

 def bulk(self, actions, **kw):
        kw.setdefault('chunk_size', 100)
        kw.setdefault('max_chunk_bytes', 5 * 1024 * 1024)
        kw.setdefault('raise_on_error', False)
        ignore_not_found = kw.pop('ignore_not_found', False)
        _, errors = es_bulk(self.es, actions, **kw)
        if errors:
            if ignore_not_found and all([e.get('delete', {}).get('status') == 404 for e in errors]):
                # This could happen, e.g. when:
                # 1. user deletes two files file2 and file2 in repo A
                # 2. ES server fails when we're updating index for repo A, file1 is deleted from index but file2 is not
                # 3. The next time when we recovery this repo, we would try to delete file1 again.
                pass
            else:
                logger.error('errors when indexing: %s', errors)
                raise Exception('errors when indexing: {}'.format(errors))

未完待续。

 

转载请注明:文章转载自 www.mshxw.com
本文地址:https://www.mshxw.com/it/676285.html
我们一直用心在做
关于我们 文章归档 网站地图 联系我们

版权所有 (c)2021-2022 MSHXW.COM

ICP备案号:晋ICP备2021003244-6号