-
Notifications
You must be signed in to change notification settings - Fork 45
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
Failed to move temporary collection file instances #15
Comments
it will show errors below after run a few times. 5573 |
@zzsoszz I see what you are trying to do, I will try to check this out later today when i get some time. |
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);
}
}
} |
I think this might be a windows quirk. I see a few people facing similar problems on windows. See: Stackoverflow Link Can you try this, check if the folder permissions has some SID information as mentioned in the link above, |
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. |
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? |
If that was a problem it would have failed each time. |
I am going to try and get a Windows machine but that is going to take a week or two. |
Could you list here the Window OS your are using? |
win 10 professional |
The text was updated successfully, but these errors were encountered: