Data Source

A MongoDB based implementation of the Space Data Source.

Library dependencies

The MongoDB SpaceClosed Where GigaSpaces data is stored. It is the logical cache that holds data objects in memory and might also hold them in layered in tiering. Data is hosted from multiple SoRs, consolidated as a unified data model. Data Source uses MongoDB Driver For communicating with the MongoDB cluster.

include the following in your pom.xml

    <!-- currently the MongoDB library is not the central maven repository --> 
    <repositories>
        <repository>
            <id>org.openspaces</id>
            <name>OpenSpaces</name>
            <url>http://maven-repository.openspaces.org</url>
        </repository>
    </repositories>


    <dependencies>
        ...
        <!-- mongodb java driver -->
        <dependency>
            <groupId>org.mongodb</groupId>
            <artifactId>mongo-java-driver</artifactId>
            <version>3.2.0</version>
        </dependency>

        <dependency> 
            <groupId>org.antlr</groupId> 
            <artifactId>antlr4-runtime</artifactId> 
            <version>4.0</version>
        </dependency> 

        <dependency>
            <groupId>org.gigaspaces</groupId>
            <artifactId>xap-mongodb</artifactId>
            <version>16.4.0-m1</version>
        </dependency>
        ...
    </dependencies>

Setup

An example of how the MongoDB Space Data Source can be configured for a space that loads data back from MongoDB once initialized and also asynchronously persists the data using a mirror (see MongoDB Space Synchronization Endpoint)).

<?xml version="1.0" encoding="utf-8"?>
<beans xmlns="http://www.springframework.org/schema/beans"
    xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xmlns:context="http://www.springframework.org/schema/context"
    xmlns:os-core="http://www.openspaces.org/schema/core" xmlns:os-jms="http://www.openspaces.org/schema/jms"
    xmlns:os-events="http://www.openspaces.org/schema/events"
    xmlns:os-remoting="http://www.openspaces.org/schema/remoting"
    xmlns:os-sla="http://www.openspaces.org/schema/sla" xmlns:tx="http://www.springframework.org/schema/tx"
    xsi:schemaLocation="http://www.springframework.org/schema/beans http://www.springframework.org/schema/beans/spring-beans.xsd
    http://www.springframework.org/schema/context http://www.springframework.org/schema/context/spring-context.xsd
    http://www.openspaces.org/schema/core http://www.openspaces.org/schema/16.4/core/openspaces-core.xsd
    http://www.openspaces.org/schema/events http://www.openspaces.org/schema/16.4/events/openspaces-events.xsd
    http://www.springframework.org/schema/tx http://www.springframework.org/schema/tx/spring-tx.xsd
    http://www.openspaces.org/schema/remoting http://www.openspaces.org/schema/16.4/remoting/openspaces-remoting.xsd">

    <bean id="propertiesConfigurer"
    class="org.springframework.beans.factory.config.PropertyPlaceholderConfigurer" />

    <os-core:embedded-space id="space" space-name="dataSourceSpace">
        space-data-source="spaceDataSource" mirrored="true" schema="persistent">
        <os-core:properties>
         <props>
            <!-- Use ALL IN CACHE, put 0 for LRUClosed Last Recently Used.
This is a common caching strategy. It defines the policy to evict elements from the cache to make room for new elements when the cache is full, meaning it discards the least recently used items first. -->
            <prop key="space-config.engine.cache_policy">1</prop>
            <prop key="cluster-config.cache-loader.central-data-source">true</prop>
            <prop key="cluster-config.mirror-service.supports-partial-update">true</prop>
         </props>
        </os-core:properties>
    </os-core:embedded-space>
        
    <os-core:giga-space id="gigaSpace" space="space" />
        
    <bean id="mongoClient" class="com.gigaspaces.persistency.MongoClientConnectorBeanFactory">
        <property name="db" value="qadb" />
        <property name="config">
            <bean class="com.mongodb.MongoClient">
                <constructor-arg value="localhost" type="java.lang.String" />
                <constructor-arg value="27017" type="int" />
            </bean>
        </property>
    </bean>
        
    <bean id="spaceDataSource" class="com.gigaspaces.persistency.MongoSpaceDataSourceBeanFactory">
        <property name="mongoClientConnector" ref="mongoClient" />
    </bean>
            
</beans>
    MongoClient config = new MongoClient(host, port);

    MongoClientConnector client = new MongoClientConnectorConfigurer()
            .client(config)
            .db(dbName)
            .create();
        
    MongoSpaceDataSource spaceDataSource = new MongoSpaceDataSourceConfigurer()
            .mongoClientConnector(client)
            .create();
    
    GigaSpace gigaSpace = new GigaSpaceConfigurer(new EmbeddedSpaceConfigurer("space")
    .schema("persistent") 
    .mirror(true) 
    .cachePolicy(new LruCachePolicy()) 
    .addProperty("cluster-config.cache-loader.central-data-source", "true") 
    .addProperty("cluster-config.mirror-service.supports-partial-update", "true") 
    .spaceDataSource(spaceDataSource) 
    .space()).gigaSpace();
For more details about different configurations see Space Persistency.

Before You Begin

Before deploying your Processing UnitClosed This is the unit of packaging and deployment in the GigaSpaces Data Grid, and is essentially the main GigaSpaces service. The Processing Unit (PU) itself is typically deployed onto the Service Grid. When a Processing Unit is deployed, a Processing Unit instance is the actual runtime entity., please do the following:

  1. Copy the xap-mongodb.jar and antlr4-runtime-4.0.jar from lib\optional\mongodb to lib\optional\pu-common.
  2. download the following jar and copy it to lib\optional\pu-common:
  3. mongo-java-driver-3.2.0.jar from mongoDB's website .

MongoSpaceDataSource Properties

Property Description Default
mongoClientConnector A configured com.gigaspaces.persistency.MongoClientConnector bean. Must be configured

Considerations

General limitations

Cache miss Query limitations

Supported queries:

  • id = 1234
  • name = 'John' AND age = 13
  • address.streetName = 'Liberty'
  • age > 15
  • age < 20
  • age <= 20
  • age >= 15
  • name = 'John' OR name = 'Jane'
  • name rlike 'A.*B'
  • name like 'A%'
  • name is NULL
  • name is NOT NULL

Java types Short, Float, BigDecimal and BigInt supported only =,<> queries >,<,>=,<= is not supported.

Unsupported Queries

Contains is unsupported.

Mongo as a Service

There are some Mongo DB hosting services that run on the cloud, and you can connect to them from your deployment environment for free. For example: mongolab

In order to configure the connection, you would need to connect using a URI that contains the username and password.

<bean id="mongoClient"
          class="com.gigaspaces.persistency.MongoClientConnectorBeanFactory">
        <property name="db" value="xapdb" />
        <property name="config">
            <bean class="com.mongodb.MongoClient">
               <constructor-arg>
                 <bean class="com.mongodb.MongoClientURI">
                   <constructor-arg value="mongodb://<DB_USERNAME>:<DB_PASSWORD>@ds027017.mongolab.com:27017/xapdb" type="java.lang.String"/>
                 </bean>
               </constructor-arg>
            </bean>
        </property>
    </bean>​