Skip to content
Projects
Groups
Snippets
Help
Loading...
Help
Support
Keyboard shortcuts
?
Submit feedback
Contribute to GitLab
Sign in / Register
Toggle navigation
J
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
preetwinder
jio
Commits
af44eae9
Commit
af44eae9
authored
Feb 08, 2016
by
Klaus Wölfel
Committed by
Romain Courteaud
Feb 22, 2016
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
ReplicateStorage: use bulk method when checking remote modification
parent
8a2bae4a
Changes
2
Show whitespace changes
Inline
Side-by-side
Showing
2 changed files
with
148 additions
and
5 deletions
+148
-5
src/jio.storage/replicatestorage.js
src/jio.storage/replicatestorage.js
+50
-5
test/jio.storage/replicatestorage.tests.js
test/jio.storage/replicatestorage.tests.js
+98
-0
No files found.
src/jio.storage/replicatestorage.js
View file @
af44eae9
...
...
@@ -309,11 +309,12 @@
}
function
checkSignatureDifference
(
queue
,
source
,
destination
,
id
,
conflict_force
,
conflict_ignore
)
{
conflict_force
,
conflict_ignore
,
getMethod
)
{
queue
.
push
(
function
()
{
return
RSVP
.
all
([
source
.
get
(
id
),
getMethod
(
id
),
context
.
_signature_sub_storage
.
get
(
id
)
]);
})
...
...
@@ -361,6 +362,35 @@
});
}
function
checkBulkSignatureDifference
(
queue
,
source
,
destination
,
id_list
,
conflict_force
,
conflict_ignore
)
{
queue
.
push
(
function
()
{
return
source
.
bulk
(
id_list
);
})
.
push
(
function
(
result_list
)
{
var
i
,
sub_queue
=
new
RSVP
.
Queue
();
function
getResult
(
j
)
{
return
function
(
id
)
{
if
(
id
!==
id_list
[
j
].
parameter_list
[
0
])
{
throw
new
Error
(
"
Does not access expected ID
"
+
id
);
}
return
result_list
[
j
];
};
}
for
(
i
=
0
;
i
<
result_list
.
length
;
i
+=
1
)
{
checkSignatureDifference
(
sub_queue
,
source
,
destination
,
id_list
[
i
].
parameter_list
[
0
],
conflict_force
,
conflict_ignore
,
getResult
(
i
));
}
return
sub_queue
;
});
}
function
pushStorage
(
source
,
destination
,
options
)
{
var
queue
=
new
RSVP
.
Queue
();
if
(
!
options
.
hasOwnProperty
(
"
use_post
"
))
{
...
...
@@ -377,6 +407,7 @@
var
i
,
local_dict
=
{},
new_list
=
[],
change_list
=
[],
signature_dict
=
{},
key
;
for
(
i
=
0
;
i
<
result_list
[
0
].
data
.
total_rows
;
i
+=
1
)
{
...
...
@@ -419,9 +450,17 @@
if
(
signature_dict
.
hasOwnProperty
(
key
))
{
if
(
local_dict
.
hasOwnProperty
(
key
))
{
if
(
options
.
check_modification
===
true
)
{
if
(
options
.
use_bulk_get
===
true
)
{
change_list
.
push
({
method
:
"
get
"
,
parameter_list
:
[
key
]
});
}
else
{
checkSignatureDifference
(
queue
,
source
,
destination
,
key
,
options
.
conflict_force
,
options
.
conflict_ignore
);
options
.
conflict_ignore
,
source
.
get
.
bind
(
source
));
}
}
}
else
{
if
(
options
.
check_deletion
===
true
)
{
...
...
@@ -430,6 +469,12 @@
}
}
}
if
((
options
.
use_bulk_get
===
true
)
&&
(
change_list
.
length
!==
0
))
{
checkBulkSignatureDifference
(
queue
,
source
,
destination
,
change_list
,
options
.
conflict_force
,
options
.
conflict_ignore
);
}
});
}
...
...
test/jio.storage/replicatestorage.tests.js
View file @
af44eae9
...
...
@@ -2332,4 +2332,102 @@
});
});
test
(
"
bulk remote document modification
"
,
function
()
{
stop
();
expect
(
5
);
var
id
,
post_id
=
"
123456789
"
,
context
=
this
;
function
Storage200Bulk
(
spec
)
{
this
.
_sub_storage
=
jIO
.
createJIO
(
spec
.
sub_storage
);
}
Storage200Bulk
.
prototype
.
bulk
=
function
(
args
)
{
deepEqual
(
args
,
[{
method
:
"
get
"
,
parameter_list
:
[
post_id
]
}]);
return
this
.
_sub_storage
.
get
(
post_id
)
.
push
(
function
(
doc
)
{
return
[
doc
];
});
};
Storage200Bulk
.
prototype
.
post
=
function
(
param
)
{
return
this
.
put
(
post_id
,
param
);
};
Storage200Bulk
.
prototype
.
put
=
function
()
{
return
this
.
_sub_storage
.
put
.
apply
(
this
.
_sub_storage
,
arguments
);
};
Storage200Bulk
.
prototype
.
hasCapacity
=
function
()
{
return
this
.
_sub_storage
.
hasCapacity
.
apply
(
this
.
_sub_storage
,
arguments
);
};
Storage200Bulk
.
prototype
.
buildQuery
=
function
()
{
return
this
.
_sub_storage
.
buildQuery
.
apply
(
this
.
_sub_storage
,
arguments
);
};
jIO
.
addStorage
(
'
replicatestorage200bulkremotemodification
'
,
Storage200Bulk
);
this
.
jio
=
jIO
.
createJIO
({
type
:
"
replicate
"
,
local_sub_storage
:
{
type
:
"
memory
"
},
remote_sub_storage
:
{
type
:
"
replicatestorage200bulkremotemodification
"
,
sub_storage
:
{
type
:
"
memory
"
}
}
});
context
.
jio
.
__storage
.
_remote_sub_storage
.
post
({
"
title
"
:
"
bar
"
})
.
then
(
function
(
result
)
{
id
=
result
;
return
context
.
jio
.
repair
();
})
.
then
(
function
()
{
return
context
.
jio
.
get
(
id
);
})
.
then
(
function
(
result
)
{
deepEqual
(
result
,
{
title
:
"
bar
"
});
})
.
then
(
function
()
{
return
context
.
jio
.
__storage
.
_signature_sub_storage
.
get
(
id
);
})
.
then
(
function
(
result
)
{
deepEqual
(
result
,
{
hash
:
"
6799f3ea80e325b89f19589282a343c376c1f1af
"
});
})
.
then
(
function
()
{
return
context
.
jio
.
__storage
.
_remote_sub_storage
.
put
(
id
,
{
"
title
"
:
"
foo
"
}
);
})
.
then
(
function
(
result
)
{
id
=
result
;
return
context
.
jio
.
repair
();
})
.
then
(
function
()
{
return
context
.
jio
.
get
(
id
);
})
.
then
(
function
(
result
)
{
deepEqual
(
result
,
{
title
:
"
foo
"
});
})
.
fail
(
function
(
error
)
{
ok
(
false
,
error
);
})
.
always
(
function
()
{
start
();
});
});
}(
jIO
,
QUnit
));
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