在线时间:8:00-16:00
迪恩网络APP
随时随地掌握行业动态
扫描二维码
关注迪恩网络微信公众号
开源软件名称:ipfs-shipyard/tevere开源软件地址:https://github.com/ipfs-shipyard/tevere开源编程语言:JavaScript 100.0%开源软件介绍:Tevere
Install$ npm install tevere --save UseHere we're using Memdown as a log database, but you can use any database that conforms to the Leveldown interface (Level-js on the browser or Leveldown on Node.js): const Tevere = require('tevere')
const Memdown = require('memdown')
const db = Tevere('partition name', {
log: Memdown('partition name')
})
db.put('key', { val: 'ue' }, (err) => {
if (err) {
throw err
}
console.log('PUT succeeded')
}) Custom merge functionBy default, when a conflict exists (two nodes have concucrently performed a change on the same key), Tevere will determinstically choose one of the values for you. Instead, you can provide a synchronous merge function like this: const db = Tevere('partition name', {
log: Memdown('partition name'),
merge: merge
})
// custom merge function that merges two records
function merge (v1, v2) {
return {
a: v1.a,
b: v2.b,
c: v1.c.concat(v2.c),
d: Math.max(v1.d, v2.d)
}
} Custom merge and determinismIf you define a custom merge function, the result must be deterministic. For every node involved in the same conflict, Tevere guarantees that the order of the values passed into the merge function is the same. In return, you must guarantee that, given the same two values, you always return the same merged value. This means that you cannot generate data that is not deterministic, like random values or even time stamps. Invalid merge function: function merge (v1, v2) {
return {
timestamp: Date.now()
}
} This is valid, though: function merge (v1, v2) {
return {
timestamp: Math.max(v1.timestamp, v2.timestamp)
}
} Tevere's compromise: Given a specific conflict, the order of the two values passed into the merge function is always the same. This means that, if two nodes have conflicting changes, both nodes custom merge functions will be called with the exact same arguments in the exact same order. Your compromise: Determinism, purely funcional merge function: given a sets of two conflicting values, you always return the same merged value, no matter at which node and at which time the merging occurs. Tevere API
|
2023-10-27
2022-08-15
2022-08-17
2022-09-23
2022-08-13
请发表评论