Skip to content
Projects
Groups
Snippets
Help
Loading...
Help
Support
Keyboard shortcuts
?
Submit feedback
Contribute to GitLab
Sign in / Register
Toggle navigation
jio
Project overview
Project overview
Details
Activity
Releases
Repository
Repository
Files
Commits
Branches
Tags
Contributors
Graph
Compare
Issues
0
Issues
0
List
Boards
Labels
Milestones
Merge Requests
0
Merge Requests
0
Analytics
Analytics
Repository
Value Stream
Wiki
Wiki
Snippets
Snippets
Members
Members
Collapse sidebar
Close sidebar
Activity
Graph
Create a new issue
Commits
Issue Boards
Open sidebar
amrani
jio
Commits
d177be73
Commit
d177be73
authored
Jan 11, 2017
by
Romain Courteaud
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
ReplicateStorage: respect configuration in all cases
parent
ab653402
Changes
2
Expand all
Show whitespace changes
Inline
Side-by-side
Showing
2 changed files
with
1028 additions
and
84 deletions
+1028
-84
src/jio.storage/replicatestorage.js
src/jio.storage/replicatestorage.js
+118
-80
test/jio.storage/replicatestorage.tests.js
test/jio.storage/replicatestorage.tests.js
+910
-4
No files found.
src/jio.storage/replicatestorage.js
View file @
d177be73
...
...
@@ -189,18 +189,7 @@
});
}
function
checkLocalDeletion
(
queue
,
destination
,
id
,
source
)
{
var
status_hash
;
queue
.
push
(
function
()
{
return
context
.
_signature_sub_storage
.
get
(
id
);
})
.
push
(
function
(
result
)
{
status_hash
=
result
.
hash
;
return
destination
.
get
(
id
)
.
push
(
function
(
doc
)
{
var
remote_hash
=
generateHash
(
stringify
(
doc
));
if
(
remote_hash
===
status_hash
)
{
function
propagateDeletion
(
destination
,
id
)
{
return
destination
.
remove
(
id
)
.
push
(
function
()
{
return
context
.
_signature_sub_storage
.
remove
(
id
);
...
...
@@ -209,20 +198,107 @@
skip_document_dict
[
id
]
=
null
;
});
}
// Modifications on remote side
// Push them locally
return
propagateModification
(
destination
,
source
,
doc
,
remote_hash
,
id
);
function
checkAndPropagate
(
status_hash
,
local_hash
,
doc
,
source
,
destination
,
id
,
conflict_force
,
conflict_revert
,
conflict_ignore
,
options
)
{
return
destination
.
get
(
id
)
.
push
(
function
(
remote_doc
)
{
return
[
remote_doc
,
generateHash
(
stringify
(
remote_doc
))];
},
function
(
error
)
{
if
((
error
instanceof
jIO
.
util
.
jIOError
)
&&
(
error
.
status_code
===
404
))
{
return
[
null
,
null
];
}
throw
error
;
})
.
push
(
function
(
remote_list
)
{
var
remote_doc
=
remote_list
[
0
],
remote_hash
=
remote_list
[
1
];
if
(
local_hash
===
remote_hash
)
{
// Same modifications on both side
if
(
local_hash
===
null
)
{
// Deleted on both side, drop signature
return
context
.
_signature_sub_storage
.
remove
(
id
)
.
push
(
function
()
{
skip_document_dict
[
id
]
=
null
;
});
}
throw
error
;
return
context
.
_signature_sub_storage
.
put
(
id
,
{
"
hash
"
:
local_hash
})
.
push
(
function
()
{
skip_document_dict
[
id
]
=
null
;
});
}
if
((
remote_hash
===
status_hash
)
||
(
conflict_force
===
true
))
{
// Modified only locally. No conflict or force
if
(
local_hash
===
null
)
{
// Deleted locally
return
propagateDeletion
(
destination
,
id
);
}
return
propagateModification
(
source
,
destination
,
doc
,
local_hash
,
id
,
{
use_post
:
((
options
.
use_post
)
&&
(
remote_hash
===
null
))});
}
// Conflict cases
if
(
conflict_ignore
===
true
)
{
return
;
}
if
((
conflict_revert
===
true
)
||
(
local_hash
===
null
))
{
// Automatically resolve conflict or force revert
if
(
remote_hash
===
null
)
{
// Deleted remotely
return
propagateDeletion
(
source
,
id
);
}
return
propagateModification
(
destination
,
source
,
remote_doc
,
remote_hash
,
id
,
{
use_post
:
((
options
.
use_revert_post
)
&&
(
local_hash
===
null
))}
);
}
// Minimize conflict if it can be resolved
if
(
remote_hash
===
null
)
{
// Copy remote modification remotely
return
propagateModification
(
source
,
destination
,
doc
,
local_hash
,
id
,
{
use_post
:
options
.
use_post
});
}
throw
new
jIO
.
util
.
jIOError
(
"
Conflict on '
"
+
id
+
"
':
"
+
stringify
(
doc
||
''
)
+
"
!==
"
+
stringify
(
remote_doc
||
''
),
409
);
});
}
function
checkLocalDeletion
(
queue
,
destination
,
id
,
source
,
conflict_force
,
conflict_revert
,
conflict_ignore
,
options
)
{
var
status_hash
;
queue
.
push
(
function
()
{
return
context
.
_signature_sub_storage
.
get
(
id
);
})
.
push
(
function
(
result
)
{
status_hash
=
result
.
hash
;
return
checkAndPropagate
(
status_hash
,
null
,
null
,
source
,
destination
,
id
,
conflict_force
,
conflict_revert
,
conflict_ignore
,
options
);
});
}
...
...
@@ -237,7 +313,7 @@
if
(
is_creation
===
true
)
{
return
RSVP
.
all
([
getMethod
(
id
),
{
hash
:
undefined
}
{
hash
:
null
}
]);
}
if
(
is_modification
===
true
)
{
...
...
@@ -256,57 +332,11 @@
status_hash
=
result_list
[
1
].
hash
;
if
(
local_hash
!==
status_hash
)
{
// Local modifications
return
destination
.
get
(
id
)
.
push
(
function
(
remote_doc
)
{
var
remote_hash
=
generateHash
(
stringify
(
remote_doc
));
if
(
remote_hash
!==
status_hash
)
{
// Modifications on both sides
if
(
local_hash
===
remote_hash
)
{
// Same modifications on both side \o/
return
context
.
_signature_sub_storage
.
put
(
id
,
{
"
hash
"
:
local_hash
})
.
push
(
function
()
{
skip_document_dict
[
id
]
=
null
;
});
}
if
(
conflict_ignore
===
true
)
{
return
;
}
if
(
conflict_revert
===
true
)
{
return
propagateModification
(
destination
,
source
,
remote_doc
,
remote_hash
,
id
);
}
if
(
conflict_force
===
false
)
{
throw
new
jIO
.
util
.
jIOError
(
"
Conflict on '
"
+
id
+
"
':
"
+
stringify
(
doc
)
+
"
!==
"
+
stringify
(
remote_doc
),
409
);
}
}
return
propagateModification
(
source
,
destination
,
doc
,
local_hash
,
id
);
},
function
(
error
)
{
var
use_post
;
if
((
error
instanceof
jIO
.
util
.
jIOError
)
&&
(
error
.
status_code
===
404
))
{
if
(
is_creation
)
{
// Remote document does not exists, create it following
// provided options
use_post
=
options
.
use_post
;
}
else
{
// Remote document has been erased, put it to save
// modification
use_post
=
false
;
}
return
propagateModification
(
source
,
destination
,
doc
,
local_hash
,
id
,
{
use_post
:
use_post
});
}
throw
error
;
});
return
checkAndPropagate
(
status_hash
,
local_hash
,
doc
,
source
,
destination
,
id
,
conflict_force
,
conflict_revert
,
conflict_ignore
,
options
);
}
});
}
...
...
@@ -350,6 +380,9 @@
if
(
!
options
.
hasOwnProperty
(
"
use_post
"
))
{
options
.
use_post
=
false
;
}
if
(
!
options
.
hasOwnProperty
(
"
use_revert_post
"
))
{
options
.
use_revert_post
=
false
;
}
return
queue
.
push
(
function
()
{
return
RSVP
.
all
([
...
...
@@ -412,7 +445,11 @@
for
(
key
in
signature_dict
)
{
if
(
signature_dict
.
hasOwnProperty
(
key
))
{
if
(
!
local_dict
.
hasOwnProperty
(
key
))
{
checkLocalDeletion
(
queue
,
destination
,
key
,
source
);
checkLocalDeletion
(
queue
,
destination
,
key
,
source
,
options
.
conflict_force
,
options
.
conflict_revert
,
options
.
conflict_ignore
,
options
);
}
}
}
...
...
@@ -502,6 +539,7 @@
return
pushStorage
(
context
.
_remote_sub_storage
,
context
.
_local_sub_storage
,
{
use_bulk_get
:
use_bulk_get
,
use_revert_post
:
context
.
_use_remote_post
,
conflict_force
:
(
context
.
_conflict_handling
===
CONFLICT_KEEP_REMOTE
),
conflict_revert
:
(
context
.
_conflict_handling
===
...
...
test/jio.storage/replicatestorage.tests.js
View file @
d177be73
This diff is collapsed.
Click to expand it.
Write
Preview
Markdown
is supported
0%
Try again
or
attach a new file
Attach a file
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Cancel
Please
register
or
sign in
to comment