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

    How to access the system workspace.


      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:




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




            Define the JCR 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:sources jcr:primaryType="nt:unstructured">



                          <mode:source jcr:name="Infinispan"






                                    mode:description="The fincayra repository source"














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



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






































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

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



                                       <BARRIER />

                                       <pbcast.NAKACK use_stats_for_retransmission="false"


                                                                               use_mcast_xmit="true" gc_lag="0"



                                       <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.FLUSH timeout="0"/>











        • 1. How to access the system workspace.

          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.

            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:




            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();






                      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;



                                          //Check if the type is in the list

                                          var property = typeManager.createPropertyDefinitionTemplate();



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



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







                      // Register the custom node type

                      typeManager.registerNodeType(template, true);


            } finally {




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

              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:





              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();
                      if (engine.getProblems().hasProblems()) {
                          for (Problem problem : engine.getProblems()) {
                      Repository repo = engine.getRepository("fincayra-repository");
                      Session session = repo.login();
                      Node rootNode = session1.getRootNode();
              • 4. Re: How to access the system workspace.

                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.

                  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.

                    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.


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



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


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





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

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

                                                               ignoreModifications="false" purgeOnStartup="false">


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





                                        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"/>






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

                      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.

                        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.

                          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.

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

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

                              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:repository jcr:name="fincayra-repository"          mode:source="FincayraSource">
                                                            <mode:options jcr:primaryType="mode:options">
                                                                      <systemSourceName jcr:primaryType="mode:option" mode:value="system@FincayraSource"/>
                                        <mode:sources jcr:primaryType="nt:unstructured">
                                                  <mode:source jcr:name="FincayraSource" mode:classname="org.modeshape.connector.store.jpa.JpaSource"
                                                            mode:predefinedWorkspaceNames="system, objects"