11 Replies Latest reply on Apr 12, 2011 1:37 PM by piascikj

    How to access the system workspace.

    piascikj

      I recently started using the SQL2 query syntax and found that in 2.4.0.Final I have to define NodeTypes and PropertyDefinitions for the nodes I will be accessing with Joins.  I was able to access the nodes after defining the types with the API using the default workspace, but upon restart I was unable to obtain a result for the same query.  I found information in Chapter 7 of the User Guide that said,

       

      Remember to specify the system workspace name for your repositories if dynamically adding or modifying node types. Otherwise, ModeShape will not persist your node type changes.

       

      Is this why my NodeType registration is not lasting between restarts?

       

      I tried repository.login("system"), but received the following exception.

       

      org.modeshape.graph.request.InvalidWorkspaceException: The workspace "system" does not exist in the "JCR Infinispan" federated repository

                at org.modeshape.graph.connector.federation.FederatedRepository.getWorkspace(FederatedRepository.java:122)

                at org.modeshape.graph.connector.federation.ForkRequestProcessor.getWorkspace(ForkRequestProcessor.java:233)

                at org.modeshape.graph.connector.federation.ForkRequestProcessor.process(ForkRequestProcessor.java:1328)

                at org.modeshape.graph.request.processor.RequestProcessor.process(RequestProcessor.java:315)

                at org.modeshape.graph.connector.federation.FederatedRepositoryConnection.execute(FederatedRepositoryConnection.java:184)

                at org.modeshape.graph.Graph.execute(Graph.java:283)

                at org.modeshape.graph.Graph$5.process(Graph.java:226)

                at org.modeshape.graph.request.RequestBuilder.verifyWorkspace(RequestBuilder.java:72)

       

      How do I specify the system workspace?

       

      Here is my configuration:

       

       

      {code:xml}

      <configuration xmlns:mode="http://www.modeshape.org/1.0" xmlns:jcr="http://www.jcp.org/jcr/1.0">

                <!--

       

       

            Define the JCR repositories

       

       

            -->

       

       

                <mode:repositories>

       

       

                          <mode:repository jcr:name="fincayra-repository"          mode:source="Infinispan">

       

       

       

                                    <mode:options jcr:primaryType="mode:options">

                                              <systemSourceName jcr:primaryType="mode:option" mode:value="system@Infinispan"/>

                                    </mode:options>

       

                          </mode:repository>

       

       

                </mode:repositories>

       

       

                <mode:sources jcr:primaryType="nt:unstructured">

       

       

                          <mode:source jcr:name="Infinispan"

       

       

                                    mode:classname="org.modeshape.connector.infinispan.InfinispanSource"

       

       

                                    mode:description="The fincayra repository source"

       

       

                                    mode:defaultworkspaceName="objects">

       

       

                                    <mode:predefinedWorkspaceNames>system</mode:predefinedWorkspaceNames>

                                    <mode:predefinedWorkspaceNames>objects</mode:predefinedWorkspaceNames>

                                    <mode:cacheConfigurationName>/grid.xml</mode:cacheConfigurationName>

                          </mode:source>

       

                </mode:sources>

       

       

                <mode:clustering clusterName="fincayra-repository-cluster">

                          <mode:configuration><![CDATA[

                                    <config>

                                       <UDP  mcast_addr="${jgroups.udp.mcast_addr:228.6.7.9}"

                                                         mcast_port="${jgroups.udp.mcast_port:46656}"

                                                         tos="8"

                                                         ucast_recv_buf_size="20000000"

                                                         ucast_send_buf_size="640000"

                                                         mcast_recv_buf_size="25000000"

                                                         mcast_send_buf_size="640000"

                                                         loopback="true"

                                                         discard_incompatible_packets="true"

                                                         max_bundle_size="64000"

                                                         max_bundle_timeout="30"

                                                         ip_ttl="${jgroups.udp.ip_ttl:2}"

                                                         enable_bundling="true"

                                                         enable_diagnostics="false"

       

       

                                                         thread_naming_pattern="pl"

       

       

                                                         thread_pool.enabled="true"

                                                         thread_pool.min_threads="2"

                                                         thread_pool.max_threads="30"

                                                         thread_pool.keep_alive_time="5000"

                                                         thread_pool.queue_enabled="false"

                                                         thread_pool.queue_max_size="100"

                                                         thread_pool.rejection_policy="Discard"

       

       

                                                         oob_thread_pool.enabled="true"

                                                         oob_thread_pool.min_threads="2"

                                                         oob_thread_pool.max_threads="30"

                                                         oob_thread_pool.keep_alive_time="5000"

                                                         oob_thread_pool.queue_enabled="false"

                                                         oob_thread_pool.queue_max_size="100"

                                                         oob_thread_pool.rejection_policy="Discard"

                                                         />

       

       

                                       <PING timeout="3000" num_initial_members="3"/>

                                       <MERGE2 max_interval="30000" min_interval="10000"/>

                                       <FD_SOCK/>

                                       <FD_ALL/>

                                       <BARRIER />

                                       <pbcast.NAKACK use_stats_for_retransmission="false"

                                                                               exponential_backoff="0"

                                                                               use_mcast_xmit="true" gc_lag="0"

                                                                               retransmit_timeout="300,600,1200"

                                                                               discard_delivered_msgs="true"/>

                                       <UNICAST timeout="300,600,1200"/>

                                       <pbcast.STABLE stability_delay="1000" desired_avg_gossip="50000" max_bytes="1000000"/>

                                       <pbcast.GMS print_local_addr="false" join_timeout="3000" view_bundling="true"/>

                                       <FC max_credits="500000" min_threshold="0.20"/>

                                       <FRAG2 frag_size="60000"  />

                                       <pbcast.STREAMING_STATE_TRANSFER/>

                                       <pbcast.FLUSH timeout="0"/>

                                    </config>

       

                          ]]>

                          </mode:configuration>

                </mode:clustering>

       

       

      </configuration>

       

      {code}

        • 1. How to access the system workspace.
          rhauch

          Is this why my NodeType registration is not lasting between restarts?

          Yes. Without specifying a system workspace, ModeShape stores the system information transiently. Simply specify that name of the system workspace as described in the manual and as you are already doing in your configuration.

           

           

          I tried repository.login("system"), but received the following exception.

          ...

           

          How do I specify the system workspace?

           

          In short, you don't. Even though you're specifying the "system" workspace (or whatever you name it) within your configuration, there is no "system" workspace available through JCR. Instead, per the JCR specification, the system information is always available in every workspace under the "/jcr:system" node.

           

          The "/jcr:system" content is a bit of a strange beast, and there are a couple of interesting characteristics of this information:

          1. The content under "/jcr:system" is indeed regular content, consisting of nodes and properties, with the structure dictated by some of the (mostly standardized) built-in node type definitions.
          2. The content under "/jcr:system" is also accessible via some of the JCR interfaces, such as NodeTypeManager, NamespaceRegistry, VersionManager, LockManager, etc. The content will change whenever these interfaces are used to change things (e.g., register a namespace, node definition, check in subgraphs, etc.).
          3. The system content is largely read-only. Technically, it's called "protected" in the node type definitions, but what that really means for JCR clients is that they can read the information but cannot change it. Instead, use the interfaces mentioned above.
          4. The stuff under "/jcr:system" in one workspace is identical to the stuff under "/jcr:system" in every other workspace in the repository. This is required per the specification.
          5. Changes to the nodes under "/jcr:system" can be monitored via the JCR event listener mechanism. This means its possible for JCR client code to watch for additions in node type definitions, namespaces, versions, locks, etc.

           

          Because of these characteristics, ModeShape actually uses the nodes under "/jcr:system" as the master storage of all namespaces, node type definitions, versions, locks, etc. for a single JCR repository, even when the repository is clustered with multiple ModeShape engines. For example, when you register a namespace using NamespaceRegistry, ModeShape will create a node representing this namespace under "/jcr:system/mode:namespaces".

           

          ModeShape handles the requirement described in #4 above by storing all the "/jcr:system" content in a separate internal (and hidden) workspace and transparently merging that content into every other workspace in the repository.

           

          Hope this helps.

          • 2. Re: How to access the system workspace.
            piascikj

            I do have a system workspace and source defined in my config, but I am still not getting any result set after restarting.

             

            Here's a look at the code.  Remember, it's javascript:

             

             

            {code}

            var session = pm.repository.login();

            var workspace = session.getWorkspace();

            var typeManager = workspace.getNodeTypeManager();

            var nodeType;

             

             

            if ($log().isDebugEnabled()) {

                      //Get all nodeTypes and debug

                      var it = typeManager.getAllNodeTypes();

                      while (it.hasNext()) {

                                var nt = it.nextNodeType();

                                $log().debug("Found node type: {}", nt.getName());

                      }

            }

             

             

            try {

                      var template;

             

             

                      if (typeManager.hasNodeType(nodeTypeName)) {

                                $log().info("NodeType [{}] is already registered.", nodeTypeName);

                                nodeType = typeManager.getNodeType(nodeTypeName);

                                template = typeManager.createNodeTypeTemplate(nodeType);

                      } else {

                                $log().info("Registering NodeType [{}] in workspace [{}].", [nodeTypeName, workspace.getName()]);

                                template = typeManager.createNodeTypeTemplate();

                                template.setDeclaredSuperTypeNames(["nt:unstructured","mix:referenceable"]);

                                template.setName(nodeTypeName);

                      }

             

             

                      for (var prop in classDef) {

                                if (classDef.hasOwnProperty(prop)) {

                                          var propSpec = classDef[prop];

                                          var rel = propSpec.rel;

                                          var type = propSpec.type;

                                          var jcrType = PropType[type] || PropType.Reference;

             

                                          //http://docs.jboss.org/modeshape/latest/manuals/reference/html/jcr.html#d0e8395

                                          //Check if the type is in the list

                                          var property = typeManager.createPropertyDefinitionTemplate();

                                          property.setName(prop);

                                          property.setRequiredType(jcrType);

                                          if (rel == Relationship.hasMany || rel == Relationship.ownsMany) {

                                                    property.setMultiple(true);

                                          }

                                          $log().info("Registering Property [{}] in nodeType [{}].", [prop, nodeTypeName]);

                                          template.getPropertyDefinitionTemplates().add(property);

                                }

                      }

             

             

             

                      // Register the custom node type

                      typeManager.registerNodeType(template, true);

                      session.save();

            } finally {

                      session.logout();

            }

            {code}

            • 3. Re: How to access the system workspace.
              rhauch

              Not sure if this is a result of pasting your configuration into the forum, but it would be an error if your configuration file contains this 4th-to-the-last line:

                    \]\]\>

                  </mode:configuration>

                </mode:clustering>

              </configuration>

              That line should be:

                    ]]>

               

              Once I fix that, I can start up the repository using your configuration file and successfully log in:

               

                      JcrEngine engine = new JcrConfiguration().loadFrom("configRepository.xml").build();
              
                      engine.start();
                      if (engine.getProblems().hasProblems()) {
                          for (Problem problem : engine.getProblems()) {
                              System.err.println(problem.getMessageString());
                          }
                      }
              
                      Repository repo = engine.getRepository("fincayra-repository");
                      Session session = repo.login();
                      Node rootNode = session1.getRootNode();
              
              
              • 4. Re: How to access the system workspace.
                piascikj

                That was a pasting error.  I can log in just fine.  My issue is with registering the NodeType and having the registration stick between restarts.

                 

                Thanks, Jesse

                • 5. Re: How to access the system workspace.
                  rhauch

                  How is your Infinispan grid defined? Is it started within your process with no persistence? If so, then when your process shuts down, so does ModeShape and so does Infinispan and any in-memory data.

                  • 6. Re: How to access the system workspace.
                    piascikj

                    My grid is clustered and is using file system persistance.  My data lives on between restarts, but my NodeType Definitions do not. 

                     

                    I can access the data after system restarts with

                     

                    SELECT * from [fincayra:User]

                     

                    Here is my infinispan config.

                    {code:xml}

                    <?xml version="1.0" encoding="UTF-8"?>

                    <infinispan>

                              <global>

                                        <transport clusterName="fincayra-grid-cluster" transportClass="org.infinispan.remoting.transport.jgroups.JGroupsTransport">

                                                  <properties>

                                                    <property name="configurationFile" value="/infinispan-cluster-udp.xml"/>

                                                  </properties>

                                        </transport>

                              </global>

                              <default>

                                         <loaders passivation="false" shared="false" preload="true">

                                                    <loader class="org.infinispan.loaders.file.FileCacheStore" fetchPersistentState="true"

                                                               ignoreModifications="false" purgeOnStartup="false">

                                                                      <properties>

                                                                                <property name="location" value="fincayra-store"/>

                                                               </properties>

                                                    </loader>

                                         </loaders>

                                        <!--

                                        This element specifies that the cache is clustered.

                                        modes supported: distribution (d), replication (r) or invalidation (i).

                                        -->

                                        <clustering mode="d">

                                                  <stateRetrieval timeout="20000" />

                                                  <sync replTimeout="200000" />

                                                  <!--<l1 enabled="true" lifespan="60000"/>-->

                                                  <hash numOwners="2" rehashRpcTimeout="60000"/>

                                        </clustering>

                              </default>

                    </infinispan>

                    {code}

                     

                    • 7. Re: How to access the system workspace.
                      rhauch

                      Forgive me, but I'm not sure what problem you're running into then. If you load your node types and data, do a restart, and can run that query, then your node types must be registered after the node type (meaning you've successfully set up the system workspace in the Infinispan source). And, earlier it sounds like your data is also there after the restart. Is that true?

                      • 8. Re: How to access the system workspace.
                        piascikj

                        I'm having to re-register the NodeType on every restart as I don' find it in my call to typeManager.hasNodeType(nodeTypeName)  So my data is persistent, but my NodeTypes and Property Definitions don't seem to be.  This may be related to the issue I recently logged about JOINs, but I couldn't say.

                        • 9. Re: How to access the system workspace.
                          rhauch

                          No, I can say for certain it is not related to the issue you logged about JOINs.

                           

                          You may want to try using the JPA connector, perhaps with HSQLDB and file-based storage. You should only have to change the "mode:source" section of your configuration file, and if it works with HSQLDB then there's something about Infinispan's configuration or the Infinispan that might not be right.

                          • 10. Re: How to access the system workspace.
                            piascikj

                            That's a good idea.  I'll give it a try.

                            • 11. Re: How to access the system workspace.
                              piascikj

                              I tried hsqldb with the following configuration with the same result.  Joins work in the first run of engine, but in subsequent runs they return empty results.

                               

                               

                              <configuration xmlns:mode="http://www.modeshape.org/1.0" xmlns:jcr="http://www.jcp.org/jcr/1.0">
                              
                              
                                        <mode:repositories>
                                                  <mode:repository jcr:name="fincayra-repository"          mode:source="FincayraSource">
                                                            <mode:options jcr:primaryType="mode:options">
                                                                      <systemSourceName jcr:primaryType="mode:option" mode:value="system@FincayraSource"/>
                                                            </mode:options>
                                                  </mode:repository>
                                        </mode:repositories>
                              
                              
                                        <mode:sources jcr:primaryType="nt:unstructured">
                                                  <mode:source jcr:name="FincayraSource" mode:classname="org.modeshape.connector.store.jpa.JpaSource"
                                                            mode:model="Simple"
                                                            mode:username="sa"
                                                            mode:password=""
                                                            mode:maximumConnectionsInPool="30"
                                                            mode:driverClassName="org.hsqldb.jdbc.JDBCDriver"
                                                            mode:url="jdbc:hsqldb:file:jcrdatabase;shutdown=true"
                                                            mode:dialect="org.hibernate.dialect.HSQLDialect"
                                                            mode:referentialIntegrityEnforced="true"
                                                            mode:largeValueSizeInBytes="1000"
                                                            mode:retryLimit="3"
                                                            mode:compressData="false"
                                                            mode:predefinedWorkspaceNames="system, objects"
                                                            mode:defaultWorkspaceName="objects"
                                                            mode:showSql="false"
                                                            mode:autoGenerateSchema="update"
                                                            mode:creatingWorkspacesAllowed="true"/>
                                        </mode:sources>
                              
                              
                              </configuration>