-
Notifications
You must be signed in to change notification settings - Fork 44
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
WIP: propose the document level ownership #271
Comments
Discussion Kick off
|
Design Doc: Document Database StorageBackgroundGoal:
Issue:[propose the document level ownership #271](#271) StructureDatabase → Collection → Document flowchart LR
A[Developers] --> B[database]
B --> C[colection 1]
C --> E[document 1]
C --> F[document 2]
C --> G[document 3]
B --> D[colection 2]
D --> H[document 4]
D --> I[document 5]
J[User] --> |"(Document, Signature, PublicKey)"|D
ID
Document serialization
Database & Collection OpDocument OP1. CreateDocumentsequenceDiagram
Client->>+Node: 1.1 CreateDocument(document)
Node->>+DocumentImpl:1.3 SubmitMutation(WRITE_DOCUMENT, document)
Node-->>-Client: 1.4 Response(status, msg)
DocumentImpl->>DocumentImpl: 2.1 documentId = GenerateDocumentId(blockId, autoId)
DocumentImpl->>+KVStore: 2.2 InsertKV(documentId, txid, document)
KVStore-->>-DocumentImpl: 2.3 Response(status, msg)
DocumentImpl-->>DocumentImpl: 2.4 index_key_pairs = GetIndexKeyPairs(db, collection, document)
loop Create Indexes: index_key_pairs.foreach
DocumentImpl-->>DocumentImpl: 2.5.1 GenerateIndexId(db, collection, documentId, index, key)
DocumentImpl->>+KVStore: 2.5.2 InsertKV(indexId, txid, documentId)
KVStore-->>-DocumentImpl: 2.5.3 Response(status, msg)
end
DocumentImpl-->>-Node: 2.6 Response(status, msg, documentId)
2. UpdateDocumentsequenceDiagram
Client->>+Node: 1.1 UpdateDocument(documentId, document)
Node->>+DocumentImpl:1.2 SubmitMutation(UpdateDocument, documentId, document)
Node-->>-Client: 1.3 Response(status, msg)
DocumentImpl->>+KVStore: 2.1 GetKV(documentId)
KVStore-->>-DocumentImpl: 2.2 Response(status, msg, address, old_document)
DocumentImpl-->>DocumentImpl: 2.3 CheckOwnership(Signature, PublicKey, address)
DocumentImpl-->>DocumentImpl: 2.4 modified_index_key_pairs = GetModifiedIndexKeyPairs(db, collection, old_document, document)
DocumentImpl->>+KVStore: 2.5 Update documet: InsertKV(documentId, txid, document)
KVStore-->>-DocumentImpl: 2.6 Response(status, msg)
DocumentImpl->>DocumentImpl: 2.7 (indexes, keys) = CheckModifiedIndexs(document, index_keys)
loop Update Indexes: modified_index_key_pairs.foreach(index, key)
DocumentImpl-->>DocumentImpl: 2.8.1 indexId = GenerateIndexId(db, collection, index, key, documentId)
DocumentImpl->>+KVStore: 2.8.2 InsertKV(indexId, txid, documentId)
KVStore-->>-DocumentImpl: 2.8.3 Response(status, msg)
end
DocumentImpl-->>-Node: 2.9 Response(status, msg)
2. DeleteDocumentsequenceDiagram
Client->>+Node: 1.1 DeleteDocument(documentId)
Node->>+DocumentImpl:1.2 SubmitMutation(DeleteDocument, documentId)
Node-->>-Client: 1.3 Response(status, msg)
DocumentImpl->>+KVStore: 2.1 GetKV(documentId)
KVStore-->>-DocumentImpl: 2.2 Response(status, msg, index_keys, txid)
DocumentImpl-->>DocumentImpl: 2.3 CheckOwnership(Signature, PublicKey, txid)
DocumentImpl->>+KVStore: 2.4 Delete documet: DeleteKV(documentId)
KVStore-->>-DocumentImpl: 2.5 Response(status, msg)
DocumentImpl-->>DocumentImpl: 2.6 index_key_pairs = GetIndexKeyPairs(db, collection, document)
loop Delete Indexes: index_key_pairs.foreach(index, key)
DocumentImpl-->>DocumentImpl: 2.7.1 GenerateIndexId(db, collection, index, key, documentId)
DocumentImpl->>+KVStore: 2.7.2 DeleteKV(indexId, txid)
KVStore-->>-DocumentImpl: 2.7.3 Response(status, msg)
end
DocumentImpl-->>-Node: 2.8 Response(status, msg)
4. GetDocumentsequenceDiagram
Client->>+Node: 1.1 GetDocumentById(documentId)
Node->>+DocumentImpl:1.3 GetDocumentById(documentId)
DocumentImpl->>+KVStore: 2.1 BatchGetKey(documentId)
KVStore-->>-DocumentImpl: 2.2 Response(status, msg, document)
DocumentImpl-->>-Node: 2.5 Response(status, msg)
Node-->>-Client: 1.4 Response(status, msg)
Client->>+Node: 2.1 GetDocuments(index, key)
Node->>+DocumentImpl:2.2 GetDocuments(index, key)
DocumentImpl->>DocumentImpl: 2.3 index_range = GenerateIndexRange(db, collection, index, key)
DocumentImpl->>+KVStore: 2.3 GetRange(index_range)
KVStore-->>-DocumentImpl: 2.4 Response(status, msg, documents)
DocumentImpl-->>-Node: 2.5 Response(status, msg, documents)
Node-->>-Client: 2.6 Response(status, msg, documents)
Implementation |
Discussion1. What is the relationship between collection and documents? 1:N or N:M?Regarding to the rpc proto definition mentioned here, one document might be under multiple collections? Will we define and implement collection in the same way? 2. Will we support Project, Namespace, Collection Group, in db3.I find those concepts are used as defined in the google firestore. |
|
RPC InterfaceDB3 will design and implement a set of APIs which are similar to google firestore so that the developers who are familiar to firestore can transfer to DB3 easily. Reference:
DB3 Admin APIThis API provides several administrative services for DB3 store. P0
P1:
DB3 Document Op APIP0: API
P1: Document API
DB3 Entity Proto
|
Milestone and resource plan
|
ImplementationBasic operation
Advance feature
|
Discussion@imotai 🔔 👀 ♨️ IndexId = |DbID(20)|CollectionId(16)|BlockID(16)| |
agree |
Propose index encode solutionGoal
ReferenceFurther work will be taken care by #321 |
Motivations
Solution
The text was updated successfully, but these errors were encountered: