Skip to content

Commit

Permalink
Keep old usage and fix account type decode err (#13903)
Browse files Browse the repository at this point in the history
1. the storage usage data could be lost when the upgrade is because there is no object info in the catalog when first replaying the old ckp.
2. correct the account type in the storage usage bat to uint64.
3. adding more tests to test the behavior of the usage cache.
4. one way to provide support is to transfer the usage to the right account.

Approved by: @XuPeng-SH, @qingxinhome
  • Loading branch information
gouhongshen authored Dec 29, 2023
1 parent 17e171d commit 71fe33a
Show file tree
Hide file tree
Showing 7 changed files with 503 additions and 138 deletions.
14 changes: 8 additions & 6 deletions pkg/frontend/show_account.go
Original file line number Diff line number Diff line change
Expand Up @@ -182,7 +182,7 @@ func handleStorageUsageResponse(
result := make(map[int32]uint64, 0)

for x := range usage.AccIds {
result[usage.AccIds[x]] = usage.Sizes[x]
result[usage.AccIds[x]] += usage.Sizes[x]
}

return result, nil
Expand All @@ -196,7 +196,7 @@ func checkStorageUsageCache(accIds [][]int32) (result map[int32]uint64, succeed
result = make(map[int32]uint64)
for x := range accIds {
for y := range accIds[x] {
size, exist := cnUsageCache.GatherAccountSize(uint32(accIds[x][y]))
size, exist := cnUsageCache.GatherAccountSize(uint64(accIds[x][y]))
if !exist {
// one missed, update all
return nil, false
Expand All @@ -220,10 +220,12 @@ func updateStorageUsageCache(accIds []int32, sizes []uint64) {

// step 2: update
for x := range accIds {
cnUsageCache.Update(logtail.UsageData{
AccId: uint32(accIds[x]),
Size: sizes[x],
})
usage := logtail.UsageData{AccId: uint64(accIds[x]), Size: sizes[x]}
if old, exist := cnUsageCache.Get(usage); exist {
usage.Size += old.Size
}

cnUsageCache.Update(usage)
}
}

Expand Down
4 changes: 2 additions & 2 deletions pkg/vm/engine/tae/catalog/database.go
Original file line number Diff line number Diff line change
Expand Up @@ -637,13 +637,13 @@ func (e *DBEntry) IsActive() bool {
}

// only for test
func MockDBEntryWithAccInfo(accId uint32, dbId uint64) *DBEntry {
func MockDBEntryWithAccInfo(accId uint64, dbId uint64) *DBEntry {
entry := &DBEntry{
ID: dbId,
}

entry.DBNode = &DBNode{}
entry.DBNode.acInfo.TenantID = accId
entry.DBNode.acInfo.TenantID = uint32(accId)

return entry
}
Loading

0 comments on commit 71fe33a

Please sign in to comment.