Comments (10)
it will show errors below after run a few times.
5573
5574
5575
5576
5577
19-01-17 10:01:37.170 ERROR [main] io.jsondb.io.JsonWriter updateInJsonFile 575 : Failed to move temporary collection file instances6294430801854422529.tmp to collection file instances.json
java.nio.file.AccessDeniedException: C:\Users\EDZ\jsondb\instances6294430801854422529.tmp -> C:\Users\EDZ\jsondb\instances.json
at sun.nio.fs.WindowsException.translateToIOException(WindowsException.java:83)
at sun.nio.fs.WindowsException.rethrowAsIOException(WindowsException.java:97)
at sun.nio.fs.WindowsFileCopy.move(WindowsFileCopy.java:301)
at sun.nio.fs.WindowsFileSystemProvider.move(WindowsFileSystemProvider.java:287)
at java.nio.file.Files.move(Files.java:1395)
at io.jsondb.io.JsonWriter.updateInJsonFile(JsonWriter.java:573)
at io.jsondb.JsonDBTemplate.findAndModify(JsonDBTemplate.java:1333)
at io.swagger.utils.GuidUtils.getUniqueId(GuidUtils.java:44)
at io.swagger.utils.GuidUtils.main(GuidUtils.java:50)
5578
5579
5580
5581
from jsondb-core.
@zzsoszz I see what you are trying to do, I will try to check this out later today when i get some time.
from jsondb-core.
I created the following Unittest copying your code with minor modifications, seems to work fine, maybe something to do with Windows
package io.jsondb.tests;
import static org.junit.Assert.assertEquals;
import java.io.File;
import org.junit.After;
import org.junit.Before;
import org.junit.Test;
import io.jsondb.JsonDBTemplate;
import io.jsondb.Util;
import io.jsondb.query.Update;
import io.jsondb.tests.model.Instance;
/**
* @version 1.0 17-Jan-2019
*/
public class FindAndModify2Tests {
private static String dbFilesLocation = "src/test/resources/dbfiles/findAndModify2Tests";
private File dbFilesFolder = new File(dbFilesLocation);
/**
* @throws java.lang.Exception
*/
@Before
public void setUp() throws Exception {
dbFilesFolder.mkdir();
}
@After
public void tearDown() throws Exception {
Util.delete(dbFilesFolder);
}
private static final Object lock = new Object();
private static volatile JsonDBTemplate instance;
private static String initValue="100000000";
public static synchronized JsonDBTemplate getJsonDBTemplate(){
JsonDBTemplate r = instance;
if (r == null) {
synchronized (lock) { // While we were waiting for the lock, another
r = instance; // thread may have instantiated the object.
if (r == null) {
r= new JsonDBTemplate(dbFilesLocation, "io.jsondb.tests.model");
instance = r;
}
}
}
return r;
}
public static String getUniqueId(){
JsonDBTemplate jsonDBTemplate=FindAndModify2Tests.getJsonDBTemplate();
if(!jsonDBTemplate.collectionExists(Instance.class)){
jsonDBTemplate.createCollection(Instance.class);
Instance instance = new Instance();
instance.setId("guid");
instance.setHostname(initValue);
jsonDBTemplate.insert(instance);
}
Instance instanceOld = jsonDBTemplate.findById("guid", Instance.class);
Update update = Update.update("hostname", Long.parseLong(instanceOld.getHostname())+1);
String jxQuery = String.format("/.[id='%s']", "guid");
Instance instanceNew = jsonDBTemplate.findAndModify(jxQuery, update, "instances");
return instanceNew.getHostname();
}
@Test
public void test() {
for(int i=1;i<=1000;i++){
String id = FindAndModify2Tests.getUniqueId();
assertEquals(Long.parseLong(initValue)+i, Long.parseLong(id));
System.out.println("Id is " + id);
}
}
}
from jsondb-core.
I think this might be a windows quirk. I see a few people facing similar problems on windows. See: Stackoverflow Link
I dont have windows system to test this theory though.
Can you try this, check if the folder permissions has some SID information as mentioned in the link above,
Or maybe the folder is marked readonly
OR maybe try closing explorer and then run the code.
from jsondb-core.
You mentioned it gives this error after running a few times.
For every update operation i first create a temporary file and then replace the existing file with the temporary file as a Atomic Move. This way the update operation will be a atomic operation. Maybe a large number of file move operations are causing a problem on windows.
from jsondb-core.
i have tried delete directory of "jsondb" and closing explorer before running and recreated directory is not "ready only",but still get this error after running a few times. i found when you moving file to destination,but the destination still exists,does it case this probolem?
from jsondb-core.
If that was a problem it would have failed each time.
from jsondb-core.
I am going to try and get a Windows machine but that is going to take a week or two.
from jsondb-core.
Could you list here the Window OS your are using?
from jsondb-core.
win 10 professional
from jsondb-core.
Related Issues (20)
- Generated resources during test execution not deleted afterwards
- No way to "flush" database HOT 2
- Provide security contact info HOT 2
- Modified json file make collectionExist return false HOT 2
- Android does not find any classes HOT 2
- Recursive data structures. Cycles not supported
- JDK 15 compliance
- jsonDBTemplate.findAll(Instance.class, comparator) HOT 4
- xpath lower-case() find. HOT 1
- ndjson parse example
- File Writes Are Not Thread Safe HOT 2
- invalid json format HOT 1
- No class found with @Document Annotation and attribute collectionName as: User, Android HOT 2
- Method for fast retrieval of collection size
- TURN OFF ERROR HANDLING IN MAVEN RELEASES, PLEASE
- Bug: Multiple SchemaUpdates (Rename) not possible
- One file for each item in a collection HOT 3
- Symlinks broken HOT 2
- getCollection always return the last item HOT 1
- Failed to acquire lock for collection file ClosedChannelException
Recommend Projects
-
React
A declarative, efficient, and flexible JavaScript library for building user interfaces.
-
Vue.js
🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.
-
Typescript
TypeScript is a superset of JavaScript that compiles to clean JavaScript output.
-
TensorFlow
An Open Source Machine Learning Framework for Everyone
-
Django
The Web framework for perfectionists with deadlines.
-
Laravel
A PHP framework for web artisans
-
D3
Bring data to life with SVG, Canvas and HTML. 📊📈🎉
-
Recommend Topics
-
javascript
JavaScript (JS) is a lightweight interpreted programming language with first-class functions.
-
web
Some thing interesting about web. New door for the world.
-
server
A server is a program made to process requests and deliver data to clients.
-
Machine learning
Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.
-
Visualization
Some thing interesting about visualization, use data art
-
Game
Some thing interesting about game, make everyone happy.
Recommend Org
-
Facebook
We are working to build community through open source technology. NB: members must have two-factor auth.
-
Microsoft
Open source projects and samples from Microsoft.
-
Google
Google ❤️ Open Source for everyone.
-
Alibaba
Alibaba Open Source for everyone
-
D3
Data-Driven Documents codes.
-
Tencent
China tencent open source team.
from jsondb-core.