Skip to content

Create basePersistDirectory only when needed - #3530

Closed
praveev wants to merge 8 commits into
apache:masterfrom
praveev:3347
Closed

Create basePersistDirectory only when needed#3530
praveev wants to merge 8 commits into
apache:masterfrom
praveev:3347

Conversation

@praveev

@praveev praveev commented Oct 4, 2016

Copy link
Copy Markdown
Contributor

@gianm is this what you had in mind for #3347?
I'm not sure how to repro and test the random tempDir creation failure tho.

@praveev

praveev commented Oct 4, 2016

Copy link
Copy Markdown
Contributor Author

hrm...thinking back. That fix may not be desirable.
Is it alright if different temp dirs (when basePersistDirectory == null ) are created on multiple calls to getBasePersistDirectory?

@gianm

gianm commented Dec 24, 2016

Copy link
Copy Markdown
Contributor

@praveev sorry for the delay. Your hunch is right, we don't want to create new temp dirs on each call to getBasePersistDirectory. The other tricky thing about this is that sometimes, things call getBasePersistDirectory even if they don't actually need to make a base persist directory.

One example where this happens is that KafkaTuningConfig gets defaults by doing RealtimeTuningConfig.makeDefaultTuningConfig(basePersistDirectory) and then calling get on the various methods, including getBasePersistDirectory. But it doesn't actually want to create the directory at that point. It might never create the directory, especially if withBasePersistDirectory is called to give it a new directory.

So what we want for #3347 is a scheme that allows the things that actually write to getBasePersistDirectory to get the behavior they need (if they call it multiple times, they should get the same response) but for things that don't write to getBasePersistDirectory to avoid triggering needless directory creations.

@praveev

praveev commented Feb 4, 2017

Copy link
Copy Markdown
Contributor Author

@gianm does using builder pattern serve this purpose? Unit test seem to pass. This ensures that those who want basePersistDirectory explicitly create it ahead of time. No creation is done in the getBasePersistDirectory() call

@gianm gianm added this to the 0.10.1 milestone Mar 2, 2017
@gianm
gianm requested review from fjy and gianm March 2, 2017 19:49

@gianm gianm left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

Thanks @praveev -- the builder stuff is nice.

Other than the line comments, one other thing: this patch looks like it works well for indexing service tasks, but doesn't work right for standalone realtime.

According to the docs, standalone realtime should use a temp dir inside java.io.tmpdir for basePersistDirectory if one isn't specified. This patch will change the default base to null rather than Files.createTempDir() which means RealtimePlumber will use the current working directory instead.

To fix this, add some code to RealtimePlumber or RealtimePlumberSchool that uses Files.createTempDir() as the basePersistDirectory if it's null.

.withMaxRowsInMemory(1)
.withVersioningPolicy(new IntervalStartVersioningPolicy())
.withRejectionPolicyFactory(new NoopRejectionPolicyFactory())
.withBasePersistDirectory(Files.createTempDir())

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

Since this is a test could you change this to use a TemporaryFolder? (The advantage is that cleanup is automatic when the test finishes, instead of leaving stuff in the user's temp dir.)

To use it just add this to your test class:

  @Rule
  public final TemporaryFolder temporaryFolder = new TemporaryFolder();

And then when you need a tmp dir get it by calling temporaryFolder.newFolder().

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

Similar comment for AppenderatorTester, although that can't have a @Rule of its own since it's not a test class. So for that one, the three test classes that call it should have a TemporaryFolder they use to generate a temp dir that they pass in to the AppenderatorTester constructor.

{
// Cannot be a static because default basePersistDirectory is unique per-instance
final RealtimeTuningConfig defaults = RealtimeTuningConfig.makeDefaultTuningConfig(basePersistDirectory);
final RealtimeTuningConfig defaults = new RealtimeTuningConfig.Builder()

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

This isn't quite right, but flows from a mistake in the original code. KafkaTuningConfig shouldn't have a basePersistDirectory. It's not documented and it doesn't make sense. (Base persist directory for tasks is set by runtime properties and always overridden via withBasePersistDirectory; so it shouldn't be provided in the task.)

Just remove basePersistDirectory from the constructor and let it stay null here.

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

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

hope i understood your comment right. i've updated the pr

@gianm

gianm commented Mar 23, 2017

Copy link
Copy Markdown
Contributor

@praveev are you able to pick this back up?

@praveev

praveev commented Mar 24, 2017

Copy link
Copy Markdown
Contributor Author

@gianm I am currently on vacation, I won't be able to get back to this until mid-April.

@gianm

gianm commented Mar 24, 2017

Copy link
Copy Markdown
Contributor

Got it, no worries, was just checking in. Looking forward to reviewing again when you get back 😄

Praveen added 5 commits April 16, 2017 11:59
# Resolved Conflicts:
#	indexing-service/src/test/java/io/druid/indexing/common/task/RealtimeIndexTaskTest.java
#	indexing-service/src/test/java/io/druid/indexing/common/task/TaskSerdeTest.java
#	indexing-service/src/test/java/io/druid/indexing/overlord/TaskLifecycleTest.java
#	server/src/main/java/io/druid/segment/indexing/RealtimeTuningConfig.java
#	server/src/test/java/io/druid/segment/realtime/RealtimeManagerTest.java
#	server/src/test/java/io/druid/segment/realtime/appenderator/AppenderatorPlumberTest.java
#	server/src/test/java/io/druid/segment/realtime/appenderator/AppenderatorTester.java
#	server/src/test/java/io/druid/segment/realtime/appenderator/DefaultOfflineAppenderatorFactoryTest.java
#	server/src/test/java/io/druid/segment/realtime/plumber/RealtimePlumberSchoolTest.java
#	server/src/test/java/io/druid/segment/realtime/plumber/SinkTest.java
#	services/src/test/java/io/druid/cli/validate/DruidJsonValidatorTest.java
@praveev

praveev commented Apr 17, 2017

Copy link
Copy Markdown
Contributor Author

@gianm Updated the PR. Not entirely sure if I understood your comment right, esp about the basePersistDirectory and KafkaTuningConfig. Please take a look and let me know.

@fjy

fjy commented May 19, 2017

Copy link
Copy Markdown
Contributor

@praveev can we finish this?

@praveev

praveev commented May 19, 2017

Copy link
Copy Markdown
Contributor Author

waiting on @gianm to review the updates

@fjy fjy modified the milestones: 0.10.2, 0.10.1 May 30, 2017
@leventov leventov modified the milestones: 0.11.0, 0.10.2 Jun 26, 2017
@jon-wei jon-wei removed this from the 0.11.0 milestone Sep 20, 2017
@jon-wei jon-wei added this to the 0.11.1 milestone Sep 20, 2017
@gianm gianm modified the milestones: 0.12.0, 0.13.0 Jan 9, 2018
@gianm

gianm commented Jan 9, 2018

Copy link
Copy Markdown
Contributor

Sorry @praveev, I totally missed this. If you are still interested in working on this patch, could you please resolve the conflicts and then we could take another look.

@jihoonson

Copy link
Copy Markdown
Contributor

The original issue (#3347) has been fixed in #5648, but this PR looks to solve another issue of postponing creating basePersistDirectory. Do we still need this? Anyway, I'll remove the milestone here.

@jihoonson jihoonson removed this from the 0.13.0 milestone Sep 17, 2018
@stale

stale Bot commented Feb 28, 2019

Copy link
Copy Markdown

This pull request has been marked as stale due to 60 days of inactivity. It will be closed in 1 week if no further activity occurs. If you think that’s incorrect or this pull request requires a review, please simply write any comment. If closed, you can revive the PR at any time and @mention a reviewer or discuss it on the dev@druid.apache.org list. Thank you for your contributions.

@stale stale Bot added the stale label Feb 28, 2019
@stale

stale Bot commented Mar 7, 2019

Copy link
Copy Markdown

This pull request has been closed due to lack of activity. If you think that is incorrect, or the pull request requires review, you can revive the PR at any time.

@stale stale Bot closed this Mar 7, 2019
seoeun25 pushed a commit to seoeun25/incubator-druid that referenced this pull request Feb 25, 2022
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Projects

None yet

Development

Successfully merging this pull request may close these issues.

6 participants