question-mark
Stuck on an issue?

Lightrun Answers was designed to reduce the constant googling that comes with debugging 3rd party libraries. It collects links to all the places you might be looking at while hunting down a tough bug.

And, if you’re still stuck at the end, we’re happy to hop on a call to see how we can help out.

program won't end (resolved) & java.nio.file.AccessDeniedException on Windows

See original GitHub issue

the following program will print done, but won’t end normally.

  def main(args: Array[String]): Unit = {
    val map1: Map[String, String, Nothing, ApiIO] = persistent.Map[String, String, Nothing, ApiIO]("map1").get
    map1.put("abc" -> "def", "123" -> "456").get
    map1.foreach(println)
      .materialize.get
    map1.close().get
    println("done")
  }

Issue Analytics

  • State:closed
  • Created 4 years ago
  • Comments:27 (18 by maintainers)

github_iconTop GitHub Comments

2reactions
simerplahacommented, Sep 8, 2020

Closing this as it is resolved. Please reopen if needed.

2reactions
simerplahacommented, Aug 28, 2020

This issue is now fixed in 0.14.6 release. All test-cases are passing on Windows 10. Please try re-running your code.

@Ectras you can now run your code without disabling mmap config.

Map<Integer, Integer, Void> map =
  MapConfig
    .functionsOff(Paths.get("data"), intSerializer(), intSerializer())
    .get();

map.put(42, 42);
System.out.println(map.get(42).get());

As mentioned before, the problem was that Windows does not allow deleting memory-mapped files unless the file’s in-memory MappedByteBuffer is cleared.

Solution

We now have a boolean cleanBeforeDelete flag in MMAP (memory-mapped) configuration. If cleanBeforeDelete is true then as the name says, memory-mapped files get cleaned before they are deleted which gets rid of the AccessDeniedException.

You don’t really have to learn these configurations at all because the default instances are already pre-configured and I will document these configurations on the website in detail but here is a basic overview if you are interested.

deleteAfterClean

In the following snippets deleteAfterClean is enabled if the operating system is Windows.

val mmap =
  MMAP.Enabled(
    deleteAfterClean = OperatingSystem.isWindows, //deleteAfterClean if OS is Windows
    forceSave = ForceSave.Disabled //disable ForceSave
  )

Java code looks like

MMAP.Enabled enabled =
  MMAP.enabled(
    OperatingSystem.isWindows(),
    ForceSave.disabled()
  );

ForceSave

ForceSave is a new configuration (#251). On Windows calling force on MappedByteBuffer is slower in certain situations (specially when copying memory-mapped) so this configuration was required. We can also disable force if we just want high performance and do not care about write guarantees on fatal machine crashes.

What is force?

force is just a function on MappedByteBuffer that “Forces any changes made to this buffer’s content to be written to the storage device containing the mapped file - JavaDoc”.

We can configure force to tell SwayDB when it should be invoked on files in any of the following 3 cases or we can disable it.

//tells SwayDB to invoke forceSave before closing a file
val beforeClose =
  ForceSave.BeforeClose(
    enableBeforeCopy = true, //also enable before copying a file
    enableForReadOnlyMode = false, //do not force save if the file is in read-only mode
    logBenchmark = true //log out time take to execute force
  )

//tells SwayDB to invoke forceSave before cleaning a memory-mapped file's MappedByteBuffer
val beforeClean =
  ForceSave.BeforeClean(
    enableBeforeCopy = true,
    enableForReadOnlyMode = true,
    logBenchmark = true
  )

//tells SwayDB to invoke forceSave before copying a file. This occurs during compaction
//where a file can simply be copied into another level without merge when there are no overlapping keys. 
val beforeCopy =
  ForceSave.BeforeCopy(
    enableForReadOnlyMode = true,
    logBenchmark = true
  )

//disables force save. 
val disabled =
  ForceSave.Disabled
Read more comments on GitHub >

github_iconTop Results From Across the Web

Getting "java.nio.file.AccessDeniedException" when trying to ...
This folder has permissions set to full control for everyone on my computer (Windows). Does anybody know why I get this exception? Here's...
Read more >
how to allow permissions to a java app deployed on tomcat
I have an application which is listening to ActiveMQ and it generates a zip file and upload it on the server. On Server...
Read more >
AccessDeniedException caused by delayed file deletion on ...
Customer has been experiencing java.nio.file.AccessDeniedException in Windows family platforms intermittently. The exception is not thrown by an illegal access ...
Read more >
Unable to start kafka with zookeeper (kafka.common ...
I solved this issue on my machine (Windows 10) by deleting the meta.properties file found in the log directory.
Read more >
Job fails randomly when using copyArtifact - Jenkins Jira
Resolution : Won't Fix ... Windows 10x64 on master and slave-nodes ... WindowsFileSystemProvider.move(Unknown Source) at java.nio.file.
Read more >

github_iconTop Related Medium Post

No results found

github_iconTop Related StackOverflow Question

No results found

github_iconTroubleshoot Live Code

Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start Free

github_iconTop Related Reddit Thread

No results found

github_iconTop Related Hackernoon Post

No results found

github_iconTop Related Tweet

No results found

github_iconTop Related Dev.to Post

No results found

github_iconTop Related Hashnode Post

No results found