0

I'm having a bit of trouble with Xodus VFS, and the application is throwing this error:

jetbrains.exodus.ExodusException: write not in progress
    at jetbrains.exodus.log.Log.ensureWriter(Log.kt:700)
    at jetbrains.exodus.log.Log.writeContinuously(Log.kt:827)
    at jetbrains.exodus.log.Log.write(Log.kt:519)
    at jetbrains.exodus.tree.patricia.MutableNode.save(MutableNode.java:324)
    at jetbrains.exodus.tree.patricia.PatriciaTreeMutable.save(PatriciaTreeMutable.java:258)
    at jetbrains.exodus.env.MetaTreeImpl.saveTree(MetaTreeImpl.java:167)
    at jetbrains.exodus.env.ReadWriteTransaction.doCommit(ReadWriteTransaction.java:248)
    at jetbrains.exodus.env.EnvironmentImpl.flushTransaction(EnvironmentImpl.java:662)
    at jetbrains.exodus.env.ReadWriteTransaction.flush(ReadWriteTransaction.java:109)
    at jetbrains.exodus.env.EnvironmentImpl.executeInTransaction(EnvironmentImpl.java:1039)
    at jetbrains.exodus.env.EnvironmentImpl.executeInTransaction(EnvironmentImpl.java:261)
    at com.backend.repository.jee.JeeXodusVFSRepository.put(JeeXodusVFSRepository.java:97)

Here's the complete code:

public com.backend.model.File put(
      String appId, String namespace, String name, InputStream is) {
    final com.backend.model.File[] createdFile = {null};
    final Environment env = manager.getEnvironment(xodusRoot, appId);
    final VirtualFileSystem vfs = manager.getVirtualFileSystem(env);
    env.executeInTransaction(
        new TransactionalExecutable() {
          @Override
          public void execute(@NotNull final Transaction txn) {
            final File file = vfs.openFile(txn, name, true);
            DataOutputStream output = new DataOutputStream(vfs.writeFile(txn, file));
            try {
              output.write(ByteStreams.toByteArray(is));
            } catch (IOException e) {
              e.printStackTrace();
            }
            createdFile[0] = new com.backend.model.File();
            createdFile[0].setDescriptor(file.getDescriptor());
            createdFile[0].setName(name);
            createdFile[0].setCreated(file.getCreated());
            createdFile[0].setModified(file.getLastModified());
          }
        });
    // vfs.shutdown();
    // env.close();
    return createdFile[0];
  }

What could be wrong in the code?

UPDATE

@Override
  public Environment getEnvironment(String xodusRoot, String instance) {
    Environment environment = environmentMap.get(xodusRoot + instance);
    if (environment == null) {
      EnvironmentConfig config = new EnvironmentConfig();
      //config.setLogDataReaderWriterProvider("jetbrains.exodus.log.replication.S3DataReaderWriterProvider");
      //config.setLogCacheShared(false);
      Environment env = Environments.newInstance(xodusRoot + instance, config);
      environmentMap.put(xodusRoot + instance, env);
    }
    Environment e = environmentMap.get(xodusRoot + instance);
    return e;
  }
quarks
  • 33,478
  • 73
  • 290
  • 513
  • What does `manager.getEnvironment(xodusRoot, appId)` do? – Vyacheslav Lukianov Nov 29 '19 at 19:38
  • It gets the environment instance from a Map since the app does not close the environment any servlet request must get the environment from the map – quarks Nov 30 '19 at 10:39
  • Do you keep `environmentMap` size limited? – Vyacheslav Lukianov Nov 30 '19 at 18:37
  • @VyacheslavLukianov Not at all is is a regular map. I managed to get around this bug, apparently, unlike Environment the VFS can be instantiated "on-the-fly" and shut down as peruse without locking issues, unlike environments, so to fix the issue I just removed VFS hash map and just instantiate it as per request. – quarks Dec 01 '19 at 02:03
  • Yes, the error looks like as a race condition, thanks for reporting. – Vyacheslav Lukianov Dec 01 '19 at 12:38
  • Did your work around also fix https://stackoverflow.com/questions/59096823/unexpected-root-page-type-99 and https://stackoverflow.com/questions/59096693/blocknotfoundexception-address-is-out-of-log-space? – Vyacheslav Lukianov Dec 01 '19 at 12:40
  • @VyacheslavLukianov the errors are gone but the problem is the VFS is returning empty stream: https://stackoverflow.com/questions/59135318/empty-stream-from-vfs – quarks Dec 02 '19 at 08:49

0 Answers0