From 9ddd20b72e621d79114275a79dd61ebfb476acdd Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?M=C3=A1rton=20Elek?= Date: Thu, 29 Sep 2022 15:24:22 +0200 Subject: [PATCH] satellite/projectaccounting: fix project usage right after the genesis After you create a brand new cluster (with storj-up, for example) the project usage fails during the first 5 minutes. The problem is the usage of `AS OF SYSTEM TIME` which points to a time where the master database didn't exist. In this specific case the database not found error can be ignored to avoid such messages. (if the database is really missing, we will have problems way more earlier, eg. at the login) Change-Id: I51ee78994d91fc2a14b56646402faaaa8154c934 --- satellite/satellitedb/projectaccounting.go | 8 ++++++++ 1 file changed, 8 insertions(+) diff --git a/satellite/satellitedb/projectaccounting.go b/satellite/satellitedb/projectaccounting.go index b21f58f14..6198eee2a 100644 --- a/satellite/satellitedb/projectaccounting.go +++ b/satellite/satellitedb/projectaccounting.go @@ -10,6 +10,7 @@ import ( "fmt" "time" + pgxerrcode "github.com/jackc/pgerrcode" "github.com/jackc/pgx/v4" "github.com/zeebo/errs" @@ -18,6 +19,7 @@ import ( "storj.io/common/uuid" "storj.io/private/dbutil" "storj.io/private/dbutil/pgutil" + "storj.io/private/dbutil/pgutil/pgerrcode" "storj.io/private/dbutil/pgxutil" "storj.io/storj/satellite/accounting" "storj.io/storj/satellite/metabase" @@ -266,6 +268,12 @@ func (db *ProjectAccounting) GetProjectDailyUsageByDateRange(ctx context.Context storageRows, err := results.Query() if err != nil { + if pgerrcode.FromError(err) == pgxerrcode.InvalidCatalogName { + // this error may happen if database is created in the last 5 minutes (`as of systemtime` points to a time before Genesis). + // in this case we can ignore the database not found error and return with no usage. + // if the database is really missing --> we have more serious problems than getting 0s from here. + return nil + } return err }