feat: add convergence layer - #39
Merged
Merged
Conversation
Yu-da-1
marked this pull request as ready for review
October 15, 2025 12:02
somasekimoto
requested changes
Nov 3, 2025
| pub struct ContentMetadata { | ||
| /// Policy type name (e.g. "lww", "text", "custom-policy"). | ||
| /// When this is `None`, it falls back to the default policy (currently "lww"). | ||
| policy_type: Option<String>, |
Contributor
There was a problem hiding this comment.
[imo]
PolicyTypeっていうenumタイプにしといたほうがいいかも?
Comment on lines
+202
to
+215
| let merge_cid = self.dag.add_child_node( | ||
| merge_node.payload().clone(), | ||
| heads.clone(), | ||
| *genesis, | ||
| merge_node.metadata().clone(), | ||
| )?; | ||
|
|
||
| let mut merge_op = Operation::new( | ||
| *genesis, | ||
| OperationType::Merge(merge_node.payload().clone()), | ||
| "auto-merge".to_string(), | ||
| ); | ||
| merge_op.parents = heads; | ||
| self.state.apply(merge_op)?; |
Contributor
There was a problem hiding this comment.
[ask]
dag.add_child_nodeと、state.apply どっちかが失敗してしまったときにデータの整合性って問題なく取れそうですか?
常に両方のデータを更新する必要がある場合は、RDBMSでいうところの "transactionを張る" という処理が必要だと思います。levelDBだと デフォルトでそういう機能はないので、writebatchとか使って自前で実装する必要がある気がしています。
| let inputs = self.collect_inputs(heads, dag)?; | ||
| let merged_payload = policy.resolve(&inputs); | ||
| let metadata = self.merge_metadata(heads, dag)?; | ||
| let timestamp = Self::current_timestamp()?; |
Contributor
There was a problem hiding this comment.
[ask]
今回の実装と外れるかもなのですが、この関数ってnano秒を返さなくていいんでしたっけ?
next_monotonic_timestamp 関数はnano秒を返してるはずで、そこと揃えなくていいのか気になりました。
Contributor
There was a problem hiding this comment.
[should]
そういえばここも失敗しちゃうと前の処理で更新したDBのデータと整合性合わない気がする
Merged
Fix/leveldb transaction
somasekimoto
approved these changes
Dec 2, 2025
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Description
convergence/を新設し、ContentMetadata・MergePolicy・ConflictResolverなどの仕組みを導入。LWW ポリシー実装を含め、ポリシー拡張の土台を整備。Repo層を拡張し、自動マージ (check_and_merge) を収束レイヤーと DAG の連携で実行。マージ操作は内部トリガーのみ許可する構造に変更。add_genesis_node/add_child_node/get_nodes_by_genesisなど因果関係を意識した命名とメタデータ保持のフローに統一。OperationTypeにMergeを追加し、マージ結果を操作履歴として保存できるようにした。CLI を新アーキテクチャに合わせて更新。Notes & open questions
ContentMetadata::policy_typeを使った拡張ポリシー設計・実装は今後の課題。OperationType::Mergeを外部から投入) は未サポート。ユースケースや安全策が固まり次第検討する。今は内部自動マージのみに限定。