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
This commit is contained in:
Márton Elek 2022-09-29 15:24:22 +02:00 committed by Storj Robot
parent 7f6f7e1246
commit 9ddd20b72e

View File

@ -10,6 +10,7 @@ import (
"fmt" "fmt"
"time" "time"
pgxerrcode "github.com/jackc/pgerrcode"
"github.com/jackc/pgx/v4" "github.com/jackc/pgx/v4"
"github.com/zeebo/errs" "github.com/zeebo/errs"
@ -18,6 +19,7 @@ import (
"storj.io/common/uuid" "storj.io/common/uuid"
"storj.io/private/dbutil" "storj.io/private/dbutil"
"storj.io/private/dbutil/pgutil" "storj.io/private/dbutil/pgutil"
"storj.io/private/dbutil/pgutil/pgerrcode"
"storj.io/private/dbutil/pgxutil" "storj.io/private/dbutil/pgxutil"
"storj.io/storj/satellite/accounting" "storj.io/storj/satellite/accounting"
"storj.io/storj/satellite/metabase" "storj.io/storj/satellite/metabase"
@ -266,6 +268,12 @@ func (db *ProjectAccounting) GetProjectDailyUsageByDateRange(ctx context.Context
storageRows, err := results.Query() storageRows, err := results.Query()
if err != nil { 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 return err
} }