-
Notifications
You must be signed in to change notification settings - Fork 1.3k
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
refactor: use epochs to gc eth tx hashes from chain indexer #12516
refactor: use epochs to gc eth tx hashes from chain indexer #12516
Conversation
@akaladarshi Will review this on Monday. Thanks for raising this ! |
@akaladarshi Please can you raise this PR against #12521 and change the GC test we already have at |
d57f643
to
3495c30
Compare
3495c30
to
6587808
Compare
chain/index/gc_test.go
Outdated
|
||
si.gc(ctx) | ||
|
||
// tipset at height 1 and 10 should be removed | ||
// tipset at height 1 data should be removed |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
dont understand this comment. what's "height 1 data" ?
chain/index/gc_test.go
Outdated
err = si.stmts.getNonRevertedTipsetEventEntriesCountStmt.QueryRow(tsKeyCid2.Bytes()).Scan(&count) | ||
require.NoError(t, err) | ||
require.Equal(t, 0, count) | ||
|
||
// tipset at height 50 should not be removed | ||
err = si.db.QueryRow("SELECT COUNT(*) FROM tipset_message WHERE height = 50").Scan(&count) |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
lot of duplication here. Can we wrap this and the two sql statements below into a function and re-use it everywhere ?
return | ||
} | ||
currHeadTime := time.Unix(int64(head.MinTimestamp()), 0) | ||
retentionDuration := time.Duration(si.gcRetentionEpochs*builtin.EpochDurationSeconds) * time.Second |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Can you add a comment explaining this calculation here ?
Why do we need time.Duration(si.gcRetentionEpochs*builtin.EpochDurationSeconds) * time.Second ?
@akaladarshi Some quick comments. |
4f59281
to
da05e17
Compare
chain/index/gc.go
Outdated
return | ||
} | ||
// Calculate the retention duration based on the number of epochs to retain. | ||
// retentionDuration represents the total duration (in nano seconds) for which data should be retained before considering it for garbage collection. |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
how is it in nanoseconds ?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
It will be seconds 👍🏾 (I will update it)
so what is happening here is we are converting EpochDurationSeconds(30) to its time duration by multiplying with time.seconds.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
@aarshkshah1992 So time.Duration
takes data in nanoseconds
(that's why I added nano seconds)
so if I just multiply time.Duration(rententionEpoch * EpochsDurationSeconds)
, it will give 600 (rententionEpoch = 20, EpochsDurationSeconds=30) but that will be in nanoseconds, to get proper time in seconds we have to multiply with time.Seconds
totalRetentionDuration := retentionDuration + graceDuration | ||
currHeadTime := time.Unix(int64(head.MinTimestamp()), 0) | ||
// gcTime is the time that is (gcRetentionEpochs + graceEpochs) in nano seconds before currHeadTime | ||
gcTime := currHeadTime.Add(-totalRetentionDuration) |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
if this is less than or equal to 0, return without doing anything. Also please can we had a test for when gcTime
<= 0 ?
|
||
log.Infof("gc'ing eth hashes older than %d days", gcRetentionDays) | ||
res, err = si.stmts.removeEthHashesOlderThanStmt.ExecContext(ctx, "-"+strconv.Itoa(int(gcRetentionDays))+" day") | ||
res, err = si.stmts.removeEthHashesBeforeTimeStmt.ExecContext(ctx, gcTime.Unix()) |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
why do we need to do .Unix()
here ?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I just wanted to provide as accurate time as possible, so I choose unix.
Thanks ! |
f2bff6f
into
filecoin-project:feat/tests-for-the-chainindexer
Fixes issue: #12465, it changes:
eth_tx_hash
query to delete before epoch instead of daysgc
function.