Uploaded image for project: 'ModeShape'
  1. ModeShape
  2. MODE-2471

Bug in infinispan cache configuration for leveldb

    XMLWordPrintable

Details

    • Bug
    • Resolution: Done
    • Major
    • 4.4.0.Final
    • 4.3.0.Final
    • Storage
    • None

    Description

      A bug exists in infinispan 7.2, where the leveldb xml configuration does not substitute java system properties for the expiration path.

      This worked in modeshape 4.2.0 since that was based on infinispan 6.0.

      I have worked out a workaround by doing the following:

          private RepositoryConfiguration initialiseRepositoryConfiguration(URL configUrl) throws Exception {
              RepositoryConfiguration config = RepositoryConfiguration.read(configUrl);
              if (config.getCacheConfiguration() == null)
                  return config; // No cache configuration specified so nothing to do
      
              InputStream cacheConfigStream = FileLookupFactory.newInstance().lookupFileStrict(config.getCacheConfiguration(), Thread.currentThread().getContextClassLoader());
              if (cacheConfigStream == null)
                  return config; // Cannot find the file so not much point in going further
      
              //
              // * Read the contents of the cache configuration stream
              // * While reading each line, check for the syntax ${xxx} and if found
              // *           replace with the associated java system property
              // * Write the new configuration out to a temporary file
              // * Set the cache configuration property to point to the temporary file instead
              // * Return a new configuration based on the edited value
              //
              BufferedReader reader = null;
              FileWriter writer = null;
              try {
                  // Read the cache configuration stream
                  reader = new BufferedReader(new InputStreamReader(cacheConfigStream));
      
                  StringBuilder builder = new StringBuilder();
                  String line;
      
                  while ((line = reader.readLine()) != null) {
                      // No need to replace properties if line does not contain any
                      if (line.contains(DOLLAR_SIGN + OPEN_BRACE)) {
                          //
                          // Calls infinispan function that SHOULD have already been called
                          //
                          line = StringPropertyReplacer.replaceProperties(line);
                      }
      
                      builder.append(line);
                      builder.append(NEW_LINE);
                  }
      
                  // Create a new temporary file for new configuration
                  String configFilePrefix = "replacement-" + config.getName(); //$NON-NLS-1$
                  File tempConfigFile = File.createTempFile(configFilePrefix, DOT + XML);
                  tempConfigFile.deleteOnExit();
                  writer = new FileWriter(tempConfigFile);
                  writer.write(builder.toString());
      
                  //
                  // Fetch the editable version of the current config and update the
                  // cache configuration path to point to the temporary file
                  //
                  Editor editor = config.edit();
                  EditableDocument storageDoc = editor.getDocument(FieldName.STORAGE);
                  storageDoc.setString(FieldName.CACHE_CONFIGURATION, tempConfigFile.getAbsolutePath());
      
                  // Create a new repository configuration based on the original
                  config = new RepositoryConfiguration(editor, configFilePrefix);
              } finally {
                  if (reader != null)
                      reader.close();
                  if (writer != null)
                      writer.close();
              }
      
              return config;
          }
      

      This finds the current cache configuration file, reads it to a string whilst detecting any '${name}' syntax and replacing them with the appropriate system property. A new configuration based on the changes is returned.

      If they is an easier way then please post a comment.

      Attachments

        Issue Links

          Activity

            People

              Unassigned Unassigned
              parichar@redhat.com Paul Richardson
              Votes:
              0 Vote for this issue
              Watchers:
              2 Start watching this issue

              Dates

                Created:
                Updated:
                Resolved: