Skip to content
GitLab
Explore
Sign in
Register
Primary navigation
Search or go to…
Project
H
hivemind
Manage
Activity
Members
Labels
Plan
Issues
Issue boards
Milestones
Wiki
Code
Merge requests
Repository
Branches
Commits
Tags
Repository graph
Compare revisions
Snippets
Deploy
Releases
Package registry
Container Registry
Model registry
Operate
Terraform modules
Monitor
Incidents
Analyze
Value stream analytics
Contributor analytics
Repository analytics
Model experiments
Help
Help
Support
GitLab documentation
Compare GitLab plans
Community forum
Contribute to GitLab
Provide feedback
Keyboard shortcuts
?
Snippets
Groups
Projects
Show more breadcrumbs
hive
hivemind
Merge requests
!144
Restoring indexes is always done
Code
Review changes
Check out branch
Download
Patches
Plain diff
Merged
Restoring indexes is always done
mt-synchronization-problem
into
develop
Overview
0
Commits
3
Pipelines
0
Changes
2
Merged
Mariusz Trela
requested to merge
mt-synchronization-problem
into
develop
4 years ago
Overview
0
Commits
3
Pipelines
0
Changes
2
Expand
0
0
Merge request reports
Compare
develop
version 2
2341ac57
4 years ago
version 1
7399e388
4 years ago
develop (base)
and
version 2
latest version
b40ca4d2
3 commits,
4 years ago
version 2
2341ac57
2 commits,
4 years ago
version 1
7399e388
1 commit,
4 years ago
2 files
+
30
−
30
Inline
Compare changes
Side-by-side
Inline
Show whitespace changes
Show one file at a time
Files
2
Search (e.g. *.vue) (Ctrl+P)
hive/db/db_state.py
+
29
−
29
Options
@@ -66,10 +66,10 @@ class DbState:
return
cls
.
_db
@classmethod
def
finish_initial_sync
(
cls
,
current_imported_block
,
last_imported_block
):
def
finish_initial_sync
(
cls
,
current_imported_block
):
"""
Set status to initial sync complete.
"""
assert
cls
.
_is_initial_sync
,
"
initial sync was not started.
"
cls
.
_after_initial_sync
(
current_imported_block
,
last_imported_block
)
cls
.
_after_initial_sync
(
current_imported_block
)
cls
.
_is_initial_sync
=
False
log
.
info
(
"
[INIT] Initial sync complete!
"
)
@@ -137,6 +137,26 @@ class DbState:
assert
not
to_locate
,
"
indexes not located: {}
"
.
format
(
to_locate
)
return
to_return
@classmethod
def
processing_indexes
(
cls
,
is_pre_process
,
drop
,
create
):
DB
=
cls
.
db
()
engine
=
DB
.
engine
()
log
.
info
(
"
[INIT] Begin %s-initial sync hooks
"
,
"
pre
"
if
is_pre_process
else
"
post
"
)
for
index
in
cls
.
_disableable_indexes
():
log
.
info
(
"
%s index %s.%s
"
,
(
"
Drop
"
if
is_pre_process
else
"
Recreate
"
),
index
.
table
,
index
.
name
)
try
:
if
drop
:
sql
=
"
SELECT count(*) FROM pg_class WHERE relname = :relname
"
_count
=
DB
.
query_one
(
sql
,
relname
=
index
.
name
)
if
_count
==
1
:
index
.
drop
(
engine
)
except
sqlalchemy
.
exc
.
ProgrammingError
as
ex
:
log
.
warning
(
"
Ignoring ex: {}
"
.
format
(
ex
))
if
create
:
index
.
create
(
engine
)
@classmethod
def
before_initial_sync
(
cls
,
last_imported_block
,
hived_head_block
):
"""
Routine which runs *once* after db setup.
@@ -150,16 +170,8 @@ class DbState:
log
.
info
(
"
[INIT] Skipping pre-initial sync hooks
"
)
return
engine
=
cls
.
db
().
engine
()
log
.
info
(
"
[INIT] Begin pre-initial sync hooks
"
)
for
index
in
cls
.
_disableable_indexes
():
log
.
info
(
"
Drop index %s.%s
"
,
index
.
table
,
index
.
name
)
try
:
index
.
drop
(
engine
)
except
sqlalchemy
.
exc
.
ProgrammingError
as
ex
:
log
.
warning
(
"
Ignoring ex: {}
"
.
format
(
ex
))
#is_pre_process, drop, create
cls
.
processing_indexes
(
True
,
True
,
False
)
from
hive.db.schema
import
drop_fk
,
set_logged_table_attribute
log
.
info
(
"
Dropping FKs
"
)
@@ -186,32 +198,20 @@ class DbState:
return
current_work_mem
@classmethod
def
_after_initial_sync
(
cls
,
current_imported_block
,
last_imported_block
):
def
_after_initial_sync
(
cls
,
current_imported_block
):
"""
Routine which runs *once* after initial sync.
Re-creates non-core indexes for serving APIs after init sync,
as well as all foreign keys.
"""
last_imported_block
=
DbState
.
db
().
query_one
(
"
SELECT block_num FROM hive_state LIMIT 1
"
)
assert
current_imported_block
>=
last_imported_block
synced_blocks
=
current_imported_block
-
last_imported_block
if
synced_blocks
>=
SYNCED_BLOCK_LIMIT
:
engine
=
cls
.
db
().
engine
()
log
.
info
(
"
[INIT] Begin post-initial sync hooks
"
)
for
index
in
cls
.
_disableable_indexes
():
log
.
info
(
"
Recreate index %s.%s
"
,
index
.
table
,
index
.
name
)
try
:
index
.
drop
(
engine
)
except
sqlalchemy
.
exc
.
ProgrammingError
as
ex
:
log
.
warning
(
"
Ignoring ex: {}
"
.
format
(
ex
))
index
.
create
(
engine
)
log
.
info
(
"
[INIT] Finish post-initial sync hooks
"
)
else
:
log
.
info
(
"
[INIT] Post-initial sync hooks skipped
"
)
#is_pre_process, drop, create
cls
.
processing_indexes
(
False
,
True
,
True
)
current_work_mem
=
cls
.
update_work_mem
(
'
2GB
'
)
Loading