diff options
author | pg9182 <96569817+pg9182@users.noreply.github.com> | 2022-10-20 01:08:12 -0400 |
---|---|---|
committer | pg9182 <96569817+pg9182@users.noreply.github.com> | 2022-10-20 01:08:12 -0400 |
commit | 6777286ba15d5bd05d0fcd9921049761bf2f59c0 (patch) | |
tree | bbb47bcda4f98ebbf0cfa9c49a21b1077ff675cf | |
parent | f0051d99fd62a3776987bb25cf7f147022c2b93b (diff) | |
download | Atlas-6777286ba15d5bd05d0fcd9921049761bf2f59c0.tar.gz Atlas-6777286ba15d5bd05d0fcd9921049761bf2f59c0.zip |
all: Make PdataStorage SetPdata return the stored pdata size
-rw-r--r-- | db/pdatadb/db.go | 10 | ||||
-rw-r--r-- | pkg/api/api0/accounts.go | 2 | ||||
-rw-r--r-- | pkg/api/api0/api0testutil/storage.go | 8 | ||||
-rw-r--r-- | pkg/api/api0/storage.go | 4 | ||||
-rw-r--r-- | pkg/memstore/memstore.go | 8 |
5 files changed, 16 insertions, 16 deletions
diff --git a/db/pdatadb/db.go b/db/pdatadb/db.go index f316dc5..b366ea3 100644 --- a/db/pdatadb/db.go +++ b/db/pdatadb/db.go @@ -127,7 +127,7 @@ func (db *DB) GetPdataCached(uid uint64, sha [sha256.Size]byte) (buf []byte, exi return obj.Pdata, true, nil } -func (db *DB) SetPdata(uid uint64, buf []byte) (err error) { +func (db *DB) SetPdata(uid uint64, buf []byte) (n int, err error) { hash := sha256.Sum256(buf) pdataHash := hex.EncodeToString(hash[:]) @@ -136,10 +136,10 @@ func (db *DB) SetPdata(uid uint64, buf []byte) (err error) { zw := gzip.NewWriter(&b) if _, err := zw.Write(buf); err != nil { - return fmt.Errorf("compress pdata: %w", err) + return 0, fmt.Errorf("compress pdata: %w", err) } if err := zw.Close(); err != nil { - return fmt.Errorf("compress pdata: %w", err) + return 0, fmt.Errorf("compress pdata: %w", err) } var pdataComp string @@ -158,7 +158,7 @@ func (db *DB) SetPdata(uid uint64, buf []byte) (err error) { "pdata_hash": pdataHash, "pdata": buf, }); err != nil { - return err + return 0, err } - return nil + return len(buf), nil } diff --git a/pkg/api/api0/accounts.go b/pkg/api/api0/accounts.go index ed95ad1..c87530e 100644 --- a/pkg/api/api0/accounts.go +++ b/pkg/api/api0/accounts.go @@ -147,7 +147,7 @@ func (h *Handler) handleAccountsWritePersistence(w http.ResponseWriter, r *http. } } - if err := h.PdataStorage.SetPdata(uid, buf); err != nil { + if _, err := h.PdataStorage.SetPdata(uid, buf); err != nil { hlog.FromRequest(r).Error(). Err(err). Uint64("uid", uid). diff --git a/pkg/api/api0/api0testutil/storage.go b/pkg/api/api0/api0testutil/storage.go index 80020fd..f6972a5 100644 --- a/pkg/api/api0/api0testutil/storage.go +++ b/pkg/api/api0/api0testutil/storage.go @@ -364,7 +364,7 @@ func TestPdataStorage(t *testing.T, s api0.PdataStorage) { } }) t.Run("PutUser1Pdata1", func(t *testing.T) { - if err := s.SetPdata(user1, pdata1); err != nil { + if _, err := s.SetPdata(user1, pdata1); err != nil { t.Fatalf("unexpected error: %v", err) } }) @@ -416,7 +416,7 @@ func TestPdataStorage(t *testing.T, s api0.PdataStorage) { } }) t.Run("PutUser1Pdata2", func(t *testing.T) { - if err := s.SetPdata(user1, pdata2); err != nil { + if _, err := s.SetPdata(user1, pdata2); err != nil { t.Fatalf("unexpected error: %v", err) } }) @@ -504,7 +504,7 @@ func TestPdataStorage(t *testing.T, s api0.PdataStorage) { } randSched() - if err := s.SetPdata(uid, data1); err != nil { + if _, err := s.SetPdata(uid, data1); err != nil { fail.Store(3) return } @@ -528,7 +528,7 @@ func TestPdataStorage(t *testing.T, s api0.PdataStorage) { } randSched() - if err := s.SetPdata(uid, data2); err != nil { + if _, err := s.SetPdata(uid, data2); err != nil { fail.Store(7) return } diff --git a/pkg/api/api0/storage.go b/pkg/api/api0/storage.go index 3fe7378..a6de4cd 100644 --- a/pkg/api/api0/storage.go +++ b/pkg/api/api0/storage.go @@ -61,6 +61,6 @@ type PdataStorage interface { // matches, buf is nil. If another error occurs, err is non-nil. GetPdataCached(uid uint64, sha [sha256.Size]byte) (buf []byte, exists bool, err error) - // SetPdata sets the raw pdata for uid. - SetPdata(uid uint64, buf []byte) (err error) + // SetPdata sets the raw pdata for uid, returning the actual size stored. + SetPdata(uid uint64, buf []byte) (n int, err error) } diff --git a/pkg/memstore/memstore.go b/pkg/memstore/memstore.go index f1421c2..ebc1956 100644 --- a/pkg/memstore/memstore.go +++ b/pkg/memstore/memstore.go @@ -103,16 +103,16 @@ func (m *PdataStore) GetPdataCached(uid uint64, sha [sha256.Size]byte) ([]byte, return b, ok, nil } -func (m *PdataStore) SetPdata(uid uint64, buf []byte) error { +func (m *PdataStore) SetPdata(uid uint64, buf []byte) (int, error) { var b []byte if m.gzip { var f bytes.Buffer w := gzip.NewWriter(&f) if _, err := w.Write(buf); err != nil { - return err + return 0, err } if err := w.Close(); err != nil { - return err + return 0, err } b = f.Bytes() } else { @@ -123,5 +123,5 @@ func (m *PdataStore) SetPdata(uid uint64, buf []byte) error { Hash: sha256.Sum256(buf), Data: b, }) - return nil + return len(b), nil } |