diff --git a/CHANGELOG.md b/CHANGELOG.md index c32b2d3062..85e4cb70eb 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -8,6 +8,10 @@ * [ct_hammer] support HTTPS and Bearer token for Authentication. * [preloader] support Bearer token Authentication for non temporal logs. +### CTFE Storage Saving: Extra Data Issuance Chain Deduplication + +* Suppress unnecessary duplicate key errors in the IssuanceChainStorage PostgreSQL implementation by @robstradling in https://github.com/google/certificate-transparency-go/pull/1678 + ## v1.3.1 * Add AllLogListSignatureURL by @AlexLaroche in https://github.com/google/certificate-transparency-go/pull/1634 diff --git a/trillian/ctfe/storage/postgresql/postgresql.go b/trillian/ctfe/storage/postgresql/postgresql.go index 241282b8fd..110c286f08 100644 --- a/trillian/ctfe/storage/postgresql/postgresql.go +++ b/trillian/ctfe/storage/postgresql/postgresql.go @@ -21,8 +21,6 @@ import ( "errors" "strings" - "github.com/jackc/pgerrcode" - "github.com/jackc/pgx/v5/pgconn" _ "github.com/jackc/pgx/v5/stdlib" "k8s.io/klog/v2" @@ -30,7 +28,7 @@ import ( const ( selectIssuanceChainByKeySQL = "SELECT c.ChainValue FROM IssuanceChain AS c WHERE c.IdentityHash = $1" - insertIssuanceChainSQL = "INSERT INTO IssuanceChain(IdentityHash, ChainValue) VALUES ($1, $2)" + insertIssuanceChainSQL = "INSERT INTO IssuanceChain(IdentityHash, ChainValue) VALUES ($1, $2) ON CONFLICT DO NOTHING" ) // IssuanceChainStorage is a PostgreSQL implementation of the IssuanceChainStorage interface. @@ -68,16 +66,7 @@ func (s *IssuanceChainStorage) FindByKey(ctx context.Context, key []byte) ([]byt // Add inserts the key-value pair of issuance chain. func (s *IssuanceChainStorage) Add(ctx context.Context, key []byte, chain []byte) error { _, err := s.db.ExecContext(ctx, insertIssuanceChainSQL, key, chain) - if err != nil { - // Ignore duplicated key error. - var postgresqlErr *pgconn.PgError - if errors.As(err, &postgresqlErr) && postgresqlErr.Code == pgerrcode.UniqueViolation { - return nil - } - return err - } - - return nil + return err } // open takes the data source name and returns the sql.DB object.