-
Notifications
You must be signed in to change notification settings - Fork 93
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
List storage jobs query API #748
List storage jobs query API #748
Conversation
Signed-off-by: Aaron Sutula <[email protected]>
Signed-off-by: Aaron Sutula <[email protected]>
Signed-off-by: Aaron Sutula <[email protected]>
Signed-off-by: Aaron Sutula <[email protected]>
Signed-off-by: Aaron Sutula <[email protected]>
Signed-off-by: Aaron Sutula <[email protected]>
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Looks good, I left some notes.
Signed-off-by: Aaron Sutula <[email protected]>
Signed-off-by: Aaron Sutula <[email protected]>
Signed-off-by: Aaron Sutula <[email protected]>
Signed-off-by: Aaron Sutula <[email protected]>
|
||
// V3StorageJobsIndexMigration contains the logic to upgrade a datastore from | ||
// version 2 to version 3. | ||
var V3StorageJobsIndexMigration = Migration{ |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Giving this all the migration "3" naming so it doesn't conflict with migration 2 that already exists in jsign/import
... will make my pending rebase easier.
"github.com/ipfs/go-datastore/query" | ||
) | ||
|
||
type storageJob struct { |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Includes only the needed parts of ffs.StorageJob
.
Run: func(ds datastoreReaderWriter) error { | ||
q := query.Query{Prefix: "/ffs/scheduler/sjstore/job"} | ||
res, err := ds.Query(q) | ||
if err != nil { | ||
return fmt.Errorf("querying sjstore jobs: %s", err) | ||
} | ||
defer func() { _ = res.Close() }() | ||
|
||
for r := range res.Next() { | ||
if r.Error != nil { | ||
return fmt.Errorf("iterating results: %s", r.Error) | ||
} | ||
|
||
var job storageJob | ||
if err := json.Unmarshal(r.Value, &job); err != nil { | ||
return fmt.Errorf("unmarshaling job: %s", err) | ||
} | ||
|
||
apiidKey := datastore.NewKey("/ffs/scheduler/sjstore/apiid").ChildString(job.APIID).ChildString(job.Cid.String()).ChildString(fmt.Sprintf("%d", job.CreatedAt)) | ||
cidKey := datastore.NewKey("/ffs/scheduler/sjstore/cid").ChildString(job.Cid.String()).ChildString(job.APIID).ChildString(fmt.Sprintf("%d", job.CreatedAt)) | ||
|
||
if err := ds.Put(apiidKey, []byte(job.ID)); err != nil { | ||
return fmt.Errorf("putting apiid index record in datastore: %s", err) | ||
} | ||
if err := ds.Put(cidKey, []byte(job.ID)); err != nil { | ||
return fmt.Errorf("putting cid index record in datastore: %s", err) | ||
} | ||
} | ||
return nil | ||
}, |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Very simple migration that simply reads all saved StorageJob
s and writes the corresponding index records for them.
// V3StorageJobsIndexMigration contains the logic to upgrade a datastore from | ||
// version 2 to version 3. | ||
var V3StorageJobsIndexMigration = Migration{ | ||
UseTxn: true, |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I don't think this is a "big" migration, so seems like this is a good idea.
t.Parallel() | ||
|
||
ds := tests.NewTxMapDatastore() | ||
|
||
pre(t, ds, "testdata/v3_StorageJobs.pre") | ||
txn, _ := ds.NewTransaction(false) | ||
|
||
err := V3StorageJobsIndexMigration.Run(txn) | ||
require.NoError(t, err) | ||
require.NoError(t, txn.Commit()) | ||
|
||
post(t, ds, "testdata/v3_StorageJobs.post") |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Not much to test here other than the data is what we expect according to the csv files.
@@ -155,6 +155,7 @@ func TestRealDataBadger(t *testing.T) { | |||
|
|||
migrations := map[int]Migration{ | |||
1: V1MultitenancyMigration, | |||
2: V3StorageJobsIndexMigration, |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Will merge this with jsign/import
and this migration will be key 3
.
Signed-off-by: Aaron Sutula <[email protected]>
// it returns a nil *ffs.Job and no-error. | ||
func (s *Store) Dequeue() (*ffs.StorageJob, error) { | ||
func (s *Store) Dequeue(iid ffs.APIID) (*ffs.StorageJob, error) { |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
FYI @jsign the new apiid arg to Dequeue
cb func(t *testing.T, s *Store, createdJobs ...createdJobs) | ||
} | ||
|
||
var testsList = []test{ |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Also FYI @jsign here's a declarative test setup I'm using to test List
.
t.Run("APIID", func(t *testing.T) { | ||
t.Parallel() | ||
s := create(t) | ||
|
||
j1 := createJob(t, "apiid1", cid.Undef) | ||
err := s.Enqueue(j1) | ||
require.NoError(t, err) | ||
|
||
j2 := createJob(t, "apiid2", cid.Undef) | ||
err = s.Enqueue(j2) | ||
require.NoError(t, err) | ||
|
||
j, err := s.Dequeue(ffs.APIID("apiid2")) | ||
require.NoError(t, err) | ||
require.Equal(t, ffs.APIID("apiid2"), j.APIID) | ||
}) |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
New test to test dequeuing a job for a specific api id.
* first cut a a list implementation for storage jobs Signed-off-by: Aaron Sutula <[email protected]> * bubble up list storage jobs api through scheduler, ffs, and apis Signed-off-by: Aaron Sutula <[email protected]> * client for list, better name for next page token Signed-off-by: Aaron Sutula <[email protected]> * list cli Signed-off-by: Aaron Sutula <[email protected]> * fix selector filter Signed-off-by: Aaron Sutula <[email protected]> * remove old/redundant code Signed-off-by: Aaron Sutula <[email protected]> * better alias Signed-off-by: Aaron Sutula <[email protected]> * pr feedback Signed-off-by: Aaron Sutula <[email protected]> * remove counts Signed-off-by: Aaron Sutula <[email protected]> * migration Signed-off-by: Aaron Sutula <[email protected]> * good tests for sjstore.List Signed-off-by: Aaron Sutula <[email protected]>
* first cut a a list implementation for storage jobs Signed-off-by: Aaron Sutula <[email protected]> * bubble up list storage jobs api through scheduler, ffs, and apis Signed-off-by: Aaron Sutula <[email protected]> * client for list, better name for next page token Signed-off-by: Aaron Sutula <[email protected]> * list cli Signed-off-by: Aaron Sutula <[email protected]> * fix selector filter Signed-off-by: Aaron Sutula <[email protected]> * remove old/redundant code Signed-off-by: Aaron Sutula <[email protected]> * better alias Signed-off-by: Aaron Sutula <[email protected]> * pr feedback Signed-off-by: Aaron Sutula <[email protected]> * remove counts Signed-off-by: Aaron Sutula <[email protected]> * migration Signed-off-by: Aaron Sutula <[email protected]> * good tests for sjstore.List Signed-off-by: Aaron Sutula <[email protected]>
* new summary api and simplified cid info Signed-off-by: Aaron Sutula <[email protected]> * pr feedback Signed-off-by: Aaron Sutula <[email protected]> * Proposed CLI package structure (#728) * move data cli commands to packages, refactor common code Signed-off-by: Aaron Sutula <[email protected]> * add data summary command that was forgotten Signed-off-by: Aaron Sutula <[email protected]> * apply cli org to the rest Signed-off-by: Aaron Sutula <[email protected]> * update docs Signed-off-by: Aaron Sutula <[email protected]> * Data summary TUI (#729) * basic tui for pow data summary Signed-off-by: Aaron Sutula <[email protected]> * pr feedback Signed-off-by: Aaron Sutula <[email protected]> * update docs Signed-off-by: Aaron Sutula <[email protected]> * List storage jobs query API (#748) * first cut a a list implementation for storage jobs Signed-off-by: Aaron Sutula <[email protected]> * bubble up list storage jobs api through scheduler, ffs, and apis Signed-off-by: Aaron Sutula <[email protected]> * client for list, better name for next page token Signed-off-by: Aaron Sutula <[email protected]> * list cli Signed-off-by: Aaron Sutula <[email protected]> * fix selector filter Signed-off-by: Aaron Sutula <[email protected]> * remove old/redundant code Signed-off-by: Aaron Sutula <[email protected]> * better alias Signed-off-by: Aaron Sutula <[email protected]> * pr feedback Signed-off-by: Aaron Sutula <[email protected]> * remove counts Signed-off-by: Aaron Sutula <[email protected]> * migration Signed-off-by: Aaron Sutula <[email protected]> * good tests for sjstore.List Signed-off-by: Aaron Sutula <[email protected]> * update pow docs Signed-off-by: Aaron Sutula <[email protected]> * fix compilation problems Signed-off-by: Aaron Sutula <[email protected]> * update docs Signed-off-by: Aaron Sutula <[email protected]> * comment exported func Signed-off-by: Aaron Sutula <[email protected]> * fix docs Signed-off-by: Ignacio Hagopian <[email protected]> * add missin cmd to cli, better name for admin jobs cli Signed-off-by: Aaron Sutula <[email protected]> Co-authored-by: Ignacio Hagopian <[email protected]>
* new summary api and simplified cid info Signed-off-by: Aaron Sutula <[email protected]> * pr feedback Signed-off-by: Aaron Sutula <[email protected]> * Proposed CLI package structure (#728) * move data cli commands to packages, refactor common code Signed-off-by: Aaron Sutula <[email protected]> * add data summary command that was forgotten Signed-off-by: Aaron Sutula <[email protected]> * apply cli org to the rest Signed-off-by: Aaron Sutula <[email protected]> * update docs Signed-off-by: Aaron Sutula <[email protected]> * Data summary TUI (#729) * basic tui for pow data summary Signed-off-by: Aaron Sutula <[email protected]> * pr feedback Signed-off-by: Aaron Sutula <[email protected]> * update docs Signed-off-by: Aaron Sutula <[email protected]> * List storage jobs query API (#748) * first cut a a list implementation for storage jobs Signed-off-by: Aaron Sutula <[email protected]> * bubble up list storage jobs api through scheduler, ffs, and apis Signed-off-by: Aaron Sutula <[email protected]> * client for list, better name for next page token Signed-off-by: Aaron Sutula <[email protected]> * list cli Signed-off-by: Aaron Sutula <[email protected]> * fix selector filter Signed-off-by: Aaron Sutula <[email protected]> * remove old/redundant code Signed-off-by: Aaron Sutula <[email protected]> * better alias Signed-off-by: Aaron Sutula <[email protected]> * pr feedback Signed-off-by: Aaron Sutula <[email protected]> * remove counts Signed-off-by: Aaron Sutula <[email protected]> * migration Signed-off-by: Aaron Sutula <[email protected]> * good tests for sjstore.List Signed-off-by: Aaron Sutula <[email protected]> * update pow docs Signed-off-by: Aaron Sutula <[email protected]> * fix compilation problems Signed-off-by: Aaron Sutula <[email protected]> * update docs Signed-off-by: Aaron Sutula <[email protected]> * comment exported func Signed-off-by: Aaron Sutula <[email protected]> * fix docs Signed-off-by: Ignacio Hagopian <[email protected]> * add missin cmd to cli, better name for admin jobs cli Signed-off-by: Aaron Sutula <[email protected]> Co-authored-by: Ignacio Hagopian <[email protected]>
The
StorageJob
s API wasn't feeling right to me, and the main problem is that there was no way to query for a list of historicalStorageJobs
. This PR implements that new API and also takes a stab at the more general problem of data paging in APIs. This newListStorageJobs
API attempts to support query options for filter by API id, filter by cid, filter by job state, limit, ascending/descending, all while also supporting data paging. It's a bit of a bespoke solution for the particular use case ofStorageJobs
, but I feel like we can use similar ideas in other places in the API where data paging is required.I want to get the bulk of the work out for preliminary PR feedback now, and will continue with the work still remaining:
sjstore
sjstore
queries.