-
-
Notifications
You must be signed in to change notification settings - Fork 189
added optional 'prune' param to file:sync(...) #3084
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
Conversation
|
@adamretter Could you please 'assign' a person from the eXist team, who is going to answer my questions and help me get this PR accepted! As a beginning I see these issues:
file:sync(
concat($common:data-path, '/', $collection),
concat('/', $repo-path, '/', $collection),
(),
true
)which is far from informative. Are there 'keyword arguments' in xquery, so that the last arg may be supplied in the form: |
| "Optional: only resources modified after the given date/time will be synchronized.") | ||
| "Optional: only resources modified after the given date/time will be synchronized."), | ||
| new FunctionParameterSequenceType("prune", Type.BOOLEAN, | ||
| Cardinality.ZERO_OR_ONE, |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
The Cardinality for this should be EXACTLY_ONE. It doesn't really make sense for this to be optional as it is a boolean value.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I've made it "optional" with the single purpose that the API remains backward compatible.
Old style invocations of file:sync(...) will still work.
If the prune param is made non-optional, then:
- Old-style invocations of that function will be rendered broken (i.e. will have to be revised)
- The previous (3rd) param of the function will also need to become non-optional, because (to the best of my understanding) you can't have optional param, followed by non-optional, right?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
That's not backwards compatible. There is no polymorphism in XQuery. You have to keep the original function signature, and then define additional function signatures with additional arities.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Wait, wait, wait.
Then (in order not to break existing code) this extended 'prune' functionality has to come together with a new function, e.g. file:sync_ex(...) or file:sync_prune(...) or something.
Is it not so?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
You don't need a new named function as they are on different arities. But you have to design two signatures, the original signature, and the new signature which has an additional argument. The new signature should then be added to the FileModule.java
extensions/modules/file/src/main/java/org/exist/xquery/modules/file/Sync.java
Show resolved
Hide resolved
extensions/modules/file/src/main/java/org/exist/xquery/modules/file/Sync.java
Outdated
Show resolved
Hide resolved
extensions/modules/file/src/main/java/org/exist/xquery/modules/file/Sync.java
Outdated
Show resolved
Hide resolved
| } | ||
| for (final Iterator<DocumentImpl> i = collection.iterator(context.getBroker()); i.hasNext(); ) { | ||
| DocumentImpl doc = i.next(); | ||
| if (startDate == null || doc.getMetadata().getLastModified() > startDate.getTime()) { |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
You should READ_LOCK the document before reading from it
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
(I am assuming you are referring to the collection when you say the document):
As far as I see on line 6 lines up (on line 152) the collection is locked and opened:
try(final Collection collection = context.getBroker().openCollection(collectionPath, LockMode.READ_LOCK))
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
You are calling doc.getMetadata().getLastModified() which is on the document, so you should read-lock the document.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
No, I am not.
Once again -- this is old code, I have not modified it.
So you see - I am trying to get a feature PR through and then it turns out the code as it was before my PR was not exactly conformant.
I don't know what is the proper way to LOCK a doc in this case (and in general).
Could you suggest the relevant change to the code and I will take it from there.
(You know I've seen GitLab gives the reviewer a way to suggest changes in the code, there should be something equivalent here)
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
try (final ManagedLock lock = broker.getBrokerPool().getLockManager().acquireDocumentLock(docUri, LockMode.READ_LOCK) { ... }
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Thanks.
You've missed one missing final - line 162: DocumentImpl doc = i.next(); ;-)
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Alternatively -- is it not a better idea (for the sake of 'Atomicity')
to read_lock the whole collection tree that is being sync-ed?
|
@sten1ee You can find tests in |
adamretter
left a comment
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
small changes needed.
|
@adamretter : you did not answer my question: And I also have this one: |
No.
There is no |
|
@adamretter in the Sync signature: new FunctionParameterSequenceType("collection", Type.STRING,
Cardinality.EXACTLY_ONE, "The collection to sync."),
new FunctionParameterSequenceType("targetPath", Type.ITEM,
Cardinality.EXACTLY_ONE, "The full path or URI to the directory"),
final String collectionPath = args[0].getStringValue();
final String target = args[1].getStringValue();
Path targetDir = FileModuleHelper.getFile(target);Why is that? |
|
I need a (xquery) hand here, in order to craft the test for this sync/4 (sync with prune) declare
%test:pending("need to mechanism to setup a temporary file to work with")
%test:assertEquals("data", "true", "true", "true")
function serialization:overwrite() {
let $node-set := text {"data"}
let $path := system:get-exist-home() || "/test.txt"
let $parameters := ()
let $append := true()
let $remove := file:delete($path)
let $ser1 := file:serialize($node-set, $path, (), false())
let $ser2 := file:serialize($node-set, $path, (), false())
let $read := file:read($path)
let $remove := file:delete($path)
return ($read, $ser1, $ser2, $remove)
};I am extremely short in XQuery skills, that's why I need help with the following test scenario:
Help needed! |
It should likely have been declared as |
|
@joewiz can i pass creating an XQsuite test on to you? I'm swamped with more pressing issues at the moment. If so can you assign yourself the ticket. |
duncdrum
left a comment
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Code looks good to me. thank you @sten1ee
We are traditionally hesitant with on-disc delete operations, is there anything preventing me to prune C:\>
You have a point here. Now back to the code:
^^^^^ |
|
related issue #2627 |
|
@line-o, are you willing to help this PR get through by authoring the required TC? |
|
@duncdrum, perhaps you haven't been notified about my reply to your question about wiping out C:> with 'prune' |
|
@sten1ee First of all, for me, just adding a prune argument is not enough. I need the ability to exclude files so that |
|
@duncdrum |
|
@line-o's suggestion about a mechanism for excluding file and folder paths and patterns makes a lot of sense, particularly given that we don't always store @sten1ee Would you be interested in adding this feature to this PR, or in a follow-on PR? I imagine this would take the form of a new I would be happy to help craft an XQSuite test. |
|
@joewiz I think I can do that, it shouldn't be that much of a work. I only need to coordinate this with (my) management as after all it is 84000 that's paying me. Apart from that, it'd be very helpful for me if you go ahead and craft some XQSuite test for the already submitted code. Why is that? I am almost sure there will be things to fix in it, problems that I missed to spot without a test. I prefer we get all this done in a single PR, but it's not that important in the end. |
|
@joewiz |
|
@joewiz, are you still willing to contribute the XQSite test, so that we can move fwd with that feature? |
|
@sten1ee Sorry for the delay, I haven't forgotten. Just working on some hard deadlines and will hope to be able to supply some tests soon. In the meantime, Duncan smartly added a skeleton XQSuite test to the issue template, so if that provides the scaffolding you needed to add a test, by all means. But if that's not sufficient, I will still follow through on creating tests as soon as I can. |
|
Just a heads up: @sten1ee your PR was discussed in todays Community Meeting. We are still committed to get it merged, but none of us has the time to prepare a test suite at the moment. As a result, this feature will not make it into the next release, which is around the corner. |
|
@sten1ee Of course, if you want to send a test-suite yourself, then we can get it merged ASAP. |
|
With #3704, I now have a technique for creating and accessing temporary directories on the filesystem, which is needed for writing tests of
file:sync(
$source-collection,
$destination-directory,
map {
"dateTime": xs:dateTime("2021-01-12T11:47:08.12-05:00"),
"prune": true(),
"excludes": array { "*.png", "*.jpg" },
"indent": false(),
"expand-xincludes": false(),
"process-xsl-pi": false(),
"encoding": "UTF-8",
"omit-xml-declaration": true()
}
)Before we merge this PR, we'd ideally discuss the direction of parameter handling and make any necessary adjustments. Thoughts? |
|
Also, just to clarify for the purposes of writing tests, I seem to recall that |
|
(Also on the topic of how file:sync serializes, see #2394.) |
|
I am in favour of an options parameter instead of separate |
|
@joewiz Yes, you are right file:sync only allows to sync to disk not from it. file:sync(
$source-collection,
$destination-directory,
map { "dateTime": xs:dateTime("2021-01-12T11:47:08.12-05:00"), ... }
)I would love to change file:sync#3 to have the options map as the third parameter. But this then means that we have an almost breaking change to the API. file:sync(
$source-collection,
$destination-directory,
xs:dateTime("2021-01-12T11:47:08.12-05:00"),
map { "prune": true() , ... }
) |
|
@line-o Great. And I actually like your idea of the hybrid 3rd parameter. We could allow |
Description:
file:sync(collection, targetPath, dateTime?)is now extended to accept another optional arg:file:sync(collection, targetPath, dateTime?, prune?)When not specified the function behaves as usual,
When specified and true,
syncwill take care to delete obsolete files and directories, i.e. it will delete any file/dir that does not correspond to a doc/collection currently in the DB.Reference:
There is no GitHub issue corresponding to this PR
Type of tests:
There are no tests for the new feature.
I could not find the tests for file:sync anyway, so point me to those, pls. I will build on top of them.