-
Notifications
You must be signed in to change notification settings - Fork 51
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
fix: Make peers sync secondary index #2390
Changes from all commits
4a2b0f7
be811d8
710d8c5
ed5ec47
669f247
b89c0a2
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -57,8 +57,8 @@ func (db *db) dropCollectionIndex( | |
return col.DropIndex(ctx, indexName) | ||
} | ||
|
||
// getAllIndexes returns all the indexes in the database. | ||
func (db *db) getAllIndexes( | ||
// getAllIndexDescriptions returns all the index descriptions in the database. | ||
func (db *db) getAllIndexDescriptions( | ||
ctx context.Context, | ||
txn datastore.Txn, | ||
) (map[client.CollectionName][]client.IndexDescription, error) { | ||
|
@@ -107,6 +107,55 @@ func (db *db) fetchCollectionIndexDescriptions( | |
return indexDescriptions, nil | ||
} | ||
|
||
func (c *collection) CreateDocIndex(ctx context.Context, doc *client.Document) error { | ||
txn, err := c.getTxn(ctx, false) | ||
if err != nil { | ||
return err | ||
} | ||
defer c.discardImplicitTxn(ctx, txn) | ||
|
||
err = c.indexNewDoc(ctx, txn, doc) | ||
if err != nil { | ||
return err | ||
} | ||
|
||
return c.commitImplicitTxn(ctx, txn) | ||
} | ||
|
||
func (c *collection) UpdateDocIndex(ctx context.Context, oldDoc, newDoc *client.Document) error { | ||
txn, err := c.getTxn(ctx, false) | ||
if err != nil { | ||
return err | ||
} | ||
defer c.discardImplicitTxn(ctx, txn) | ||
|
||
err = c.deleteIndexedDoc(ctx, txn, oldDoc) | ||
if err != nil { | ||
return err | ||
} | ||
err = c.indexNewDoc(ctx, txn, newDoc) | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. nitpick: I do see There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Can you expand on what is your nitpick concern here Andy? There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. I have none and thought I was in the txn_db.go file :) There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Ah I see I how I got confused - they have moved to collection, and I new that they had moved, but my brain still thought of the implementation as being in the txn_db file when I saw the txn logic. I wonder if we can do a similar job to collection that we did to client.Store and split out the txn boilerplate to another file sometime |
||
if err != nil { | ||
return err | ||
} | ||
|
||
return c.commitImplicitTxn(ctx, txn) | ||
} | ||
|
||
func (c *collection) DeleteDocIndex(ctx context.Context, doc *client.Document) error { | ||
txn, err := c.getTxn(ctx, false) | ||
if err != nil { | ||
return err | ||
} | ||
defer c.discardImplicitTxn(ctx, txn) | ||
|
||
err = c.deleteIndexedDoc(ctx, txn, doc) | ||
if err != nil { | ||
return err | ||
} | ||
|
||
return c.commitImplicitTxn(ctx, txn) | ||
} | ||
|
||
func (c *collection) indexNewDoc(ctx context.Context, txn datastore.Txn, doc *client.Document) error { | ||
err := c.loadIndexes(ctx, txn) | ||
if err != nil { | ||
|
@@ -133,7 +182,8 @@ func (c *collection) updateIndexedDoc( | |
oldDoc, err := c.get( | ||
ctx, | ||
txn, | ||
c.getPrimaryKeyFromDocID(doc.ID()), c.Definition().CollectIndexedFields(), | ||
c.getPrimaryKeyFromDocID(doc.ID()), | ||
c.Definition().CollectIndexedFields(), | ||
false, | ||
) | ||
if err != nil { | ||
|
@@ -148,6 +198,24 @@ func (c *collection) updateIndexedDoc( | |
return nil | ||
} | ||
|
||
func (c *collection) deleteIndexedDoc( | ||
ctx context.Context, | ||
txn datastore.Txn, | ||
doc *client.Document, | ||
) error { | ||
err := c.loadIndexes(ctx, txn) | ||
if err != nil { | ||
return err | ||
} | ||
for _, index := range c.indexes { | ||
err = index.Delete(ctx, txn, doc) | ||
if err != nil { | ||
return err | ||
} | ||
} | ||
return nil | ||
} | ||
|
||
// CreateIndex creates a new index on the collection. | ||
// | ||
// If the index name is empty, a name will be automatically generated. | ||
|
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.
praise: These are suitably scary - thanks 😁
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 second that 👍