Skip to content
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

HPCC-19489 STD.File.RenameLogicalFile should support OVERWRITE #11607

Conversation

AttilaVamos
Copy link
Contributor

@AttilaVamos AttilaVamos commented Aug 28, 2018

Add allowOverwrite parameter to STD.File.RenameLogicalFile

Add code if overwrite is allowed to:

  • check source and target file existence
  • remove existing target file

Extend fileservice.ecl to test allowOverwrite option

Signed-off-by: Attila Vamos attila.vamos@gmail.com

Type of change:

  • This change is a bug fix (non-breaking change which fixes an issue).
  • This change is a new feature (non-breaking change which adds functionality).
  • This change improves the code (refactor or other change that does not change the functionality)
  • This change fixes warnings (the fix does not alter the functionality or the generated code)
  • This change is a breaking change (fix or feature that will cause existing behavior to change).
  • This change alters the query API (existing queries will have to be recompiled)

Checklist:

  • My code follows the code style of this project.
    • My code does not create any new warnings from compiler, build system, or lint.
  • The commit message is properly formatted and free of typos.
    • The commit message title makes sense in a changelog, by itself.
    • The commit is signed.
  • My change requires a change to the documentation.
    • I have updated the documentation accordingly, or...
    • I have created a JIRA ticket to update the documentation.
    • Any new interfaces or exported functions are appropriately commented.
  • I have read the CONTRIBUTORS document.
  • The change has been fully tested:
    • I have added tests to cover my changes.
    • All new and existing tests passed.
    • I have checked that this change does not introduce memory leaks.
    • I have used Valgrind or similar tools to check for potential issues.
  • I have given due consideration to all of the following potential concerns:
    • Scalability
    • Performance
    • Security
    • Thread-safety
    • Premature optimization
    • Existing deployed queries will not be broken
    • This change fixes the problem, not just the symptom
    • The target branch of this pull request is appropriate for such a change.
  • There are no similar instances of the same problem that should be addressed
    • I have addressed them here
    • I have raised JIRA issues to address them separately
  • This is a user interface / front-end modification
    • I have tested my changes in multiple modern browsers
    • The component(s) render as expected

Testing:

Changes are tested manually.

@hpcc-jirabot
Copy link

@AttilaVamos
Copy link
Contributor Author

@jakesmith please review

@@ -523,31 +523,63 @@ FILESERVICES_API void FILESERVICES_CALL fsSetReadOnly(ICodeContext *ctx, const c
throw error.getClear();
}


FILESERVICES_API void FILESERVICES_CALL fsRenameLogicalFile(ICodeContext *ctx, const char *oldname, const char *newname)
FILESERVICES_API void FILESERVICES_CALL implementRenameLogicalFile(ICodeContext *ctx, const char *oldname, const char *newname, const bool overwrite)
{
StringBuffer lfn, nlfn;
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

pedantic/not new: but would be slightly clearer if lfn was olfn, or these were oldLfn/newLfn or similar.

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Changed

if (overwrite)
{
if ( distributedDirectory.exists(nlfn.str(), ctx->queryUserDescriptor(), false, false) &&
distributedDirectory.exists(lfn.str(), ctx->queryUserDescriptor(), false, false))
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

If old lfn doesn't exist, there's no point in continuing at all, with or without overwrite. (renamePhysical will fail).
So would be clearer if checked if old existed and error out before anything else.

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Changed

s.append("') done");
WUmessage(ctx, SeverityInformation, NULL, s.str());
AuditMessage(ctx, "DeleteLogicalFile", nlfn.str());
}
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

lines 541 to 552 are same as code in fsDeleteLogicalFile.
should be commoned up, i.e. both call common function, or possibly for this just to calll fsDeleteLogicalFile directly.

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Changed

OUTPUT(ds, , prefix + 'renametest.d00', OVERWRITE),
OUTPUT(ds, , prefix + 'afterrename1.d00', OVERWRITE),
// Remane with overwrite allowed
File.RenameLogicalFile(prefix + 'renametest.d00', prefix + 'afterrename1.d00', true),
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I think there may be some untested problems.

  1. Rename external or foreign with overwrite.
    Both are disallowed and will error on rename, but the delete will have already happened..
    Foreign delete should fail, so may be ok.
    External delete .. I'm not sure, worth testing.
    i.e. need to make sure it doesn't succeed to delete - but then fail on rename.
  2. Rename in a transaction.
    Actually fileservices.ecl doesn't have any transaction tests at the moment.
    I think there may be problems with rename in particular, related to the way delete happens.
    See addDelayedDelete/CDelayedDelete in dadfs.cpp

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

As we discussed, I will test this delete, rename in transaction.

File.DeleteLogicalFile(prefix + 'scope1::afterrename3.d00'),
OUTPUT(ds, , prefix + 'renametest.d00', OVERWRITE),
OUTPUT(ds, , prefix + 'afterrename1.d00', OVERWRITE),
// Remane with overwrite allowed
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

typo: Rename

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Changed

OUTPUT(ds, , prefix + 'afterrename1.d00', OVERWRITE),
// Remane with overwrite allowed
File.RenameLogicalFile(prefix + 'renametest.d00', prefix + 'afterrename1.d00', true),
File.DeleteLogicalFile(prefix + 'afterrename1.d00'),
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Would be good to read the renamed file after the test to verify before deleting it.

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Added

@jakesmith
Copy link
Member

@AttilaVamos - added some comments.

@AttilaVamos
Copy link
Contributor Author

@jakesmith updated, please re-review.

@HPCCSmoketest
Copy link
Contributor

Automated Smoketest: ✅
OS: centos 7.4.1708 (Linux 3.10.0-327.28.3.el7.x86_64)
Sha: 6581d6d
Build: success
Install hpccsystems-platform-community_7.0.0-rc1.el7.x86_64.rpm
HPCC Start: OK

Unit tests result:

Test total passed failed errors timeout
unittest 94 94 0 0 0
wutoolTest(Dali) 19 19 0 0 0
wutoolTest(Cassandra) 19 19 0 0 0

Regression test result:

phase total pass fail
setup (hthor) 11 11 0
setup (thor) 11 11 0
setup (roxie) 11 11 0
test (hthor) 805 805 0
test (thor) 729 729 0
test (roxie) 878 878 0

HPCC Stop: OK
HPCC Uninstall: OK
Time stats:

Prep time Build time Package time Install time Start time Test time Stop time Summary
16 sec (00:00:16) 173 sec (00:02:53) 93 sec (00:01:33) 20 sec (00:00:20) 42 sec (00:00:42) 1365 sec (00:22:45) 19 sec (00:00:19) 1728 sec (00:28:48)

@jakesmith
Copy link
Member

@AttilaVamos - looks good, but 1 question.

Did the "As we discussed, I will test this delete, rename in transaction." happen, is there a separate JIRA?

@richardkchapman
Copy link
Member

@AttilaVamos Please squash

@AttilaVamos
Copy link
Contributor Author

@jakesmith I will open a JIRA or perhaps two to cover rename logical file in transaction, for foreign and external file.

@jakesmith
Copy link
Member

@AttilaVamos - please squash ready for merge and reference the new JIRA's in this issues JIRA.

Add allowOverwrite parameter to STD.File.RenameLogicalFile

Add code if overwrite is allowed to:
- check source and target file existence
- remove existing target file

Extend fileservice.ecl to test allowOverwrite option

Signed-off-by: Attila Vamos <attila.vamos@gmail.com>
@richardkchapman richardkchapman merged commit 7c1df82 into hpcc-systems:master Sep 7, 2018
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
5 participants