Infinispan cache.put does not work - infinispan

I have created a two node cluster running Infinispan cache in replication mode. I see the cache comes up fine. and both the nodes connect to each other. I am here using TreeCache Api to convert the Map based structure to tree based as below:
private static Cache<Object, Object> Cache1;
private static TreeCache<Object, Object> Cache;
Cache1 = new DefaultCacheManager("infinispan.xml").getCache();
Cache = new TreeCacheFactory().createTreeCache(Cache1);
If i call Cache.put , I dont get any error but the entry does not get saved to the cache. I confirmed it by getting the data again which returns NULL.
Cache.put(fqn,key, value);
if(Cache.get(fqn, key) == null)
{
System.out.println("Entry is not saved");
}
Below is the config file,
<?xml version="1.0" encoding="UTF-8"?>
<infinispan xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
xsi:schemaLocation="urn:infinispan:config:5.3 http://www.infinispan.org/schemas/infinispan-config-5.3.xsd"
xmlns="urn:infinispan:config:5.3">
<global>
<globalJmxStatistics enabled = "true" allowDuplicateDomains = "true"/>
<transport clusterName = "test_cluster">
<properties>
<property name="configurationFile" value="tcp.xml" />
</properties>
</transport>
</global>
<default>
<clustering mode="replication">
<async asyncMarshalling="true" useReplQueue="true" replQueueInterval="10" replQueueMaxElements="100" />
<stateTransfer timeout="2000000"/>
</clustering>
<invocationBatching enabled = "true"/>
<locking isolationLevel = "REPEATABLE_READ"
writeSkewCheck = "false"
concurrencyLevel = "1000"/>
<jmxStatistics enabled="true"/>
</default>
</infinispan>
Is it that I am missing to initialize any thing?

Related

Infinispan local cache error: Unable to invoke method public void org.infinispan.globalstate.impl.GlobalConfigurationManagerImpl.start()

I have upgraded a Spring boot service to Infinispan 9.4.16.Final from 5.2.20.Final. The service has two XML files. I used the conversion script to convert them. Both have local-cache entries and no other types of caches. One was left with empty transport element by the conversion tool.
When we deploy and run these services, we often see this warning at startup:
org.infinispan.manager.EmbeddedCacheManagerStartupException: org.infinispan.commons.CacheException: Unable to invoke method public void org.infinispan.globalstate.impl.GlobalConfigurationManagerImpl.start() on object of type GlobalConfigurationManagerImpl
The above is the first warning/error we see. There is no stack trace. Why would it be calling GlobalConfigurationManagerImpl when we're only using local cache?
A few lines later in the log, then I see many The cache has been stopped and invocations are not allowed! errors. The last error we see is as follows. The service fails to start up successfully.
Caused by: org.infinispan.commons.CacheException: Initial state transfer timed out for cache org.infinispan.CONFIG on <server_name>
Why are these errors/warnings happening on startup? Is there a problem in the config files? I've searched online and have not found a solution.
~~More Info~~~
Here is one of the two XML config files:
<infinispan
xmlns:xsi = "http://www.w3.org/2001/XMLSchema-instance"
xsi:schemaLocation = "urn:infinispan:config:9.4 http://www.infinispan.org/schemas/infinispan-config-9.4.xsd"
xmlns = "urn:infinispan:config:9.4">
<threads/>
<cache-container name = "TestCenterServiceCache">
<!-- The conversion tool added this empty "transport" element. It was not present in our old config file -->
<transport/>
<jmx domain = "org.infinispan.TestCenterServiceCache"/>
<local-cache name = "authorizedLocations">
<expiration lifespan = "3600000"/>
</local-cache>
<!--caching for 24 hours: 3,600,000 milliseconds/hr x 24 hours -->
<local-cache name = "proximitySearchConfiguration">
<expiration lifespan = "86400000"/>
</local-cache>
</cache-container>
</infinispan>
The above is instantiated via applicationContext.xml. The first warning (GlobalConfigurationManagerImpl.start()) is referencing these beans.
<bean id="infinispanCacheManager"
class="org.infinispan.spring.embedded.support.InfinispanEmbeddedCacheManagerFactoryBean"
p:configurationFileLocation="classpath:testCenterServices-cache-config.xml" />
<bean id="cacheManager"
class="org.infinispan.spring.embedded.provider.SpringEmbeddedCacheManager">
<constructor-arg ref="infinispanCacheManager" />
</bean>
Here is the second XML config file:
<?xml version="1.0" ?>
<infinispan
xmlns:xsi = "http://www.w3.org/2001/XMLSchema-instance"
xsi:schemaLocation = "urn:infinispan:config:9.4 http://www.infinispan.org/schemas/infinispan-config-9.4.xsd"
xmlns = "urn:infinispan:config:9.4">
<threads />
<cache-container name="AtlasServicesCacheManager">
<local-cache name="allLocaleCache" />
<local-cache name="localeCacheByID" />
<local-cache name="countryByCode" />
<local-cache name="allActiveCountries" />
<local-cache name="allCountries" />
<local-cache name="allStatesForCountryCode" />
<local-cache name="allActiveStatesForCountryCode" />
<local-cache name="stateForCountryCodeStateCode" />
</cache-container>
</infinispan>
The above is instantiated via java code.
#Bean(name="atlasServicesCacheManager")
public CacheManager makeCacheManager() throws IOException {
return new SpringEmbeddedCacheManager(new DefaultCacheManager("atlas-cache-config.xml"));
}
I don't know if it's meaningful, but only after the upgrade, we log messages that include "JGroups", such as Unable to use any JGroups configuration mechanisms provided in properties {}. Using default JGroups configuration!.
The service instances are running on Windows Server 2012 R2 Standard (Windows 8).
To fix this, remove the empty <transport /> element for local caches.
Adding that empty element seems to be a defect in the config-converter. With the empty transport element in place, it seems that Infinispan is partially configured for cluster synchronization. For details on the underlying issue, see bug report: https://issues.redhat.com/browse/ISPN-11854.

Data is not persisted in ModeShape 3.8

Recently I started working on a project using ModeShape 3.8 and Infinispan 5.3. Original developer already left without any documentation. Application is working fine unless it is not restarted. All data was lost as soon as it is shutdown. May be some transient repository but not sure.
In the pom.xml
modeshape-jcr
modeshape-jcr-api
modeshape-schematic
modeshape-bom-embedded
infinispan-core
In the repo.json
{
"name":"repo",
"workspaces":{
"default":"default",
"allowCreation":true
},
"security":{"providers" : [
{
"name" : "Custom Provider",
"classname" : "security.CustomRepoAuthProvider"
}
]
},
"storage":{
"cacheConfiguration":"/conf/infinispan-conf.xml",
"cacheName":"filesystem"
}
}
In the infinispan-conf.xml
http://www.infinispan.org/schemas/infinispan-config-5.3.xsd">
<global>
<globalJmxStatistics enabled="false" allowDuplicateDomains="true"/>
</global>
<namedCache name="filesystem">
<transaction transactionManagerLookupClass="org.infinispan.transaction.lookup.GenericTransactionManagerLookup" transactionMode="TRANSACTIONAL" lockingMode="OPTIMISTIC"/>
<loaders passivation="false" shared="false" preload="true">
<fileStore fetchPersistentState="true" purgerThreads="3" purgeSynchronously="true" ignoreModifications="false" purgeOnStartup="false" location="/lfs/enve/apps/tomcat/temp/">
<async enabled="true" flushLockTimeout="15000" threadPoolSize="5" />
<singletonStore enabled="true" pushStateWhenCoordinator="true" pushStateTimeout="20000" />
</fileStore>
</loaders>
</namedCache>
Any body help me???
In the infinispan-conf.xml made following changes
http://www.infinispan.org/schemas/infinispan-config-5.3.xsd">
<global>
<globalJmxStatistics enabled="false" allowDuplicateDomains="true"/>
</global>
<namedCache name="filesystem">
<locking isolationLevel="READ_COMMITTED"/>
<transaction
transactionManagerLookupClass="org.infinispan.transaction.lookup.GenericTransactionManagerLookup"
transactionMode="TRANSACTIONAL"
lockingMode="PESSIMISTIC"/>
<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="/lfs/envd/apps/tomcat/temp/"/>
</properties>
</loader>
</loaders>
</namedCache>
Your file store is writing to "/lfs/enve/apps/tomcat/temp/"
My guess is that you are deleting the temp directory when you are restarting tomcat. You would need to make sure to write it to a more "permanent" directory.

Deploying Custom RoleMapper to WebLogic

I am trying to deploy a Custom Role Mapper in WebLogic 10.3.5.0 - this is very similar to this question - Weblogic Providers, but I cannot get the provider to appear in the poplist.
Config file:
<MBeanType Name="DatabaseRoleMapping"
DisplayName="DatabaseRoleMapping"
Package="com.bynx.weblogic.mbean.rolemapping"
Extends="weblogic.management.security.authorization.RoleMapper"
PersistPolicy = "OnUpdate">
<MBeanAttribute
Name = "ProviderClassName"
Type = "java.lang.String"
Writeable = "false"
Preprocessor = "weblogic.management.configuration.LegalHelper.checkClassName(value)"
Default = ""com.bynx.weblogic.mbean.rolemapping.DatabaseRoleMappingProvider""
/>
<MBeanAttribute
Name = "Description"
Type = "java.lang.String"
Writeable = "false"
Default = ""Provider that performs Role Mapping held in a database""
/>
<MBeanAttribute
Name = "Version"
Type = "java.lang.String"
Writeable = "false"
Default = ""1.0""
/>
<!--
<MBeanAttribute
Name = "DataSourceJNDI"
Type = "java.lang.String"
Default = ""UserDataSource""
Description = "DataSource JNDI name"
/> -->
</MBeanType>
Provider Imlementation:
package com.bynx.weblogic.mbean.rolemapping;
import weblogic.management.security.ProviderMBean;
import weblogic.security.spi.RoleMapper;
import weblogic.security.spi.RoleProvider;
import weblogic.security.spi.SecurityServices;
public class DatabaseRoleMappingProvider implements RoleProvider
{
DatabaseRoleMapper mapper;
private String description;
#Override
public String getDescription()
{
return description;
}
#Override
public void initialize(ProviderMBean provider, SecurityServices services)
{
//DatabaseRoleMappingProviderMBean mBean = (DatabaseRoleMappingProviderMBean)provider;
//mapper = new DatabaseRoleMapper(mBean.getDataSourceJNDI());
mapper = new DatabaseRoleMapper("UserDataSource");
description = provider.getName() + " " + provider.getVersion();
}
#Override
public void shutdown()
{
}
#Override
public RoleMapper getRoleMapper()
{
return mapper;
}
}
Build file:
<?xml version="1.0"?>
<project name="dbuser_authentication_provider" default="all" basedir=".">
<!-- global properties -->
<property environment="env"/>
<property name="jdk" value="C:/Program Files (x86)/Java/jdk1.6.0_26"/>
<property name="lib" value="P:/Web_Dev/Projects/WebLogic_Home/wlserver_10.3/server/lib"/>
<property name="mbeantypes" value="${lib}/mbeantypes"/>
<property name="sampleprovidersjar" value="databaseRoleMapping.jar"/>
<property name="sample_dir" location="."/>
<property name="src_dir" value="${sample_dir}/src"/>
<property name="provider_src_dir" value="${src_dir}/com"/>
<property name="build_dir" value="${sample_dir}/build"/>
<property name="class_dir" value="${sample_dir}/classes"/>
<property name="namespace" value="http://www.bea.com/ns/90/weblogic/security/samples"/>
<target name="all" depends="clean">
<!-- Set up the build directories -->
<mkdir dir="${build_dir}"/>
<mkdir dir="${class_dir}"/>
<!-- Only copy over the commo dtd and sample provider xml files for now -->
<copy todir="${build_dir}" flatten="true">
<fileset dir="${lib}">
<include name="commo.dtd"/>
</fileset>
</copy>
<copy todir="${build_dir}" flatten="true">
<fileset dir="${provider_src_dir}">
<include name="**/*.xml"/>
<include name="**/*.java"/>
</fileset>
</copy>
<!-- Build the sample security providers' jar file -->
<java classname="weblogic.management.commo.WebLogicMBeanMaker" fork="true" failonerror="true">
<jvmarg line="-cp '${jdk}/lib/tools.jar';${lib}/weblogic.jar -Dfiles=${build_dir} -DMDFDIR=${build_dir} -DMJF=${build_dir}/${sampleprovidersjar} -DtargetNameSpace=${namespace} -DpreserveStubs=true -DcreateStubs=true"/>
</java>
</target>
<target name="clean">
<delete quiet="true" dir="${build_dir}"/>
<delete quiet="true" dir="${class_dir}"/>
</target>
</project>
Everything compiles fine and there don't appear to be any missing class files in the generated jar, but putting the jar in the mbeantypes directory and restarting it doesn't appear in the list. It will eventually look at a database, but I have stripped it down to the minimum to try and get it working. Any suggestions - or where to look in the logs for any issues would be appreciated.
I've managed to get this working, so thought I would share my solution in case anyone else stumbles upon this.
First the statement in the documentation:
However, if you want WebLogic Server to look for MBean types in additional directories, use the -Dweblogic.alternateTypesDirectory= command-line flag when starting your server, where is a comma-separated list of directory names. When you use this flag, WebLogic Server will always load MBean types from WL_HOME\server\lib\mbeantypes first, then will look in the additional directories and load all valid archives present in those directories (regardless of their extension).
Doesn't appear to be correct. We are using the alternateTypesDirectory parameter and I could only get WebLogic to pickup my custom MBean if I put the jar in one of the directories in the command-line flag.
Secondly, if you have anything deployed that uses versioning (e.g. one or more of the optional deployable libraries), your custom provider must implement the weblogic.security.spi.VersionableApplicationProvider interface and haveImplements = "weblogic.management.security.ApplicationVersioner" in the MBeanType element of the definition XML.

Multiple DataCacheClients - Strange configuration behaviour

I am using Azure's In-Role caching for our web role cluster.
I need to use separate dataCacheClients so to have different and explicitly set transport property configurations (maxBufferPoolSize and maxBufferSize).
The problem is that each dataCacheClient is always set with the same maxBufferPoolSize and maxBufferSize values. They are all set to the values from the dataCacheFactory which I instantiate first.
<dataCacheClients>
<dataCacheClient name="DataCache1">
<autoDiscover isEnabled="true" identifier="MyRoleName" />
<transportProperties maxBufferPoolSize="6400000" maxBufferSize="256" />
</dataCacheClient>
<dataCacheClient name="DataCache2">
<autoDiscover isEnabled="true" identifier="MyRoleName" />
<transportProperties maxBufferPoolSize="0" maxBufferSize="10485760" />
</dataCacheClient>
<dataCacheClient name="DataCache3">
<autoDiscover isEnabled="true" identifier="MyRoleName" />
<transportProperties maxBufferPoolSize="3276800" maxBufferSize="32768" />
</dataCacheClient>
</dataCacheClients>
Each concrete DataCache object is instantiated from separate DataCacheFactory instances (contained inside static 'managers'). I have also tried reverting to creating the cache clients programmatically, but to no avail.
So, here is an exception being thrown due to MaxBufferSize being too small at 256.
When debugging the factory, you can clearly see that the MaxBufferSize is not 256:
I am starting to pull my hair out, so I've come up with the two ideas:
My suspicion is that the StartPort and DiscoveryPort in each data clients' AutoDiscoveryProperties are the same across all (22233 as StartPort and 24233 as DiscoveryPort), which makes me believe that they could be pulling from the same factory (and thus using the same settings).
In addition, the DataCacheServerEndpoint for each client is also the same, at 20004. Perhaps they need to be different?
I am using Microsoft.WindowsAzure.Caching 2.4.0.0 and Azure SDK 2.4.
Can anyone help point me in the right direction?
It seems your problem is not client site, but server side. Make sure your maxBufferSize at your server is the right size, sample configuration msdn:
<?xml version="1.0" encoding="utf-8" ?>
<configuration>
<!--configSections must be the FIRST element -->
<configSections>
<!-- required to read the <dataCacheClient> element -->
<section name="dataCacheClient"
type="Microsoft.ApplicationServer.Caching.DataCacheClientSection,
Microsoft.ApplicationServer.Caching.Core, Version=1.0.0.0,
Culture=neutral, PublicKeyToken=31bf3856ad364e35"
allowLocation="true"
allowDefinition="Everywhere"/>
</configSections>
<dataCacheClient requestTimeout="15000" channelOpenTimeout="3000" maxConnectionsToServer="1">
<localCache isEnabled="true" sync="TimeoutBased" ttlValue="300" objectCount="10000"/>
<clientNotification pollInterval="300" maxQueueLength="10000"/>
<hosts>
<host name="CacheServer1" cachePort="22233"/>
<host name="CacheServer2" cachePort="22233"/>
</hosts>
<securityProperties mode="Transport" protectionLevel="EncryptAndSign" />
<transportProperties connectionBufferSize="131072" maxBufferPoolSize="268435456"
maxBufferSize="8388608" maxOutputDelay="2" channelInitializationTimeout="60000"
receiveTimeout="600000"/>
</dataCacheClient>
</configuration>
Azure host configuration
Try using the following snippet:
// DataCacheFactoryConfiguration encapsulates the datacache client section of the config.
DataCacheFactoryConfiguration dcfc1 = new DataCacheFactoryConfiguration("DataCache1");
DataCacheFactory dcf1 = new DataCacheFactory(dcfc1);
DataCache dc1 = dcf1.GetDefaultCache();
Alternatively you can configure it programmatically:
// This will create an instance of DataCacheFactoryConfiguration from default datacache client in config.
DataCacheFactoryConfiguration dcfc = new DataCacheFactoryConfiguration();
//You can then set the buffer size as you wish and create DataCacheFactory and DataCache after that.
dcfc.TransportProperties.MaxBufferSize = size;
DataCacheFactory dcf = new DataCacheFactory(dcfc);
DataCache dc = dcf.GetDefaultCache();
Edit1: I created two different client using two different factories and I can see both of them having different max buffer size.
DataCacheFactoryConfiguration dcfc = new DataCacheFactoryConfiguration();
dcfc.TransportProperties.MaxBufferSize = 8388608;
DataCacheFactory dcf = new DataCacheFactory(dcfc);
DataCache dc = dcf.GetDefaultCache();
DataCacheFactoryConfiguration dcfc1 = new DataCacheFactoryConfiguration();
dcfc1.TransportProperties.MaxBufferSize = 8388;
DataCacheFactory dcf1 = new DataCacheFactory(dcfc1);
DataCache dc1 = dcf1.GetDefaultCache();

error in creating EntityManager object

I am trying to create a EntityManager object for persistence and I am unable to create EntityManager object. Please find the sample code below:
EntityManagerFactory emf = Persistence.createEntityManagerFactory("Draco-PU");
EntityManager em = emf.createEntityManager();
I have defined the persistence unit name in persistence.xml file too.
<persistence-unit name="Draco-PU" >
The persistence xml is as defined below:
<?xml version="1.0" encoding="UTF-8"?>
<persistence version="1.0" xmlns="http://java.sun.com/xml/ns/persistence"
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
xsi:schemaLocation="http://java.sun.com/xml/ns/persistence http://java.sun.com/xml/ns
/persistence/persistence_1_0.xsd">
<persistence-unit name="Draco-PU" >
<provider>org.apache.openjpa.persistence.PersistenceProviderImpl</provider>
<jta-data-source>DracoDataSource</jta-data-source>
<non-jta-data-source>DracoUnmanagedDataSource</non-jta-data-source>
<class>dk.tdc.soa.smo.draco.db.model.DslServiceEntity</class>
<class>dk.tdc.soa.smo.draco.db.model.DslServiceCatalogEntity</class>
<class>dk.tdc.soa.smo.draco.db.model.History</class>
<class>dk.tdc.soa.smo.draco.db.model.ConfigEntity</class>
<properties>
<property name="openjpa.Log" value="DefaultLevel=WARNING, Runtime=WARNING, Tool=WARNING, SQL=WARNING" />
<!-- <property name="openjpa.jdbc.DBDictionary" value="org.apache.openjpa.jdbc.sql.OracleDictionary" /> -->
<property name="openjpa.jdbc.SynchronizeMappings" value="buildSchema(ForeignKeys=true)" />
</properties>
</persistence-unit>
</persistence>
The error faced is :
javax.persistence.PersistenceException: No Persistence provider for EntityManager
named Draco-PU: Provider named kodo.persistence.PersistenceProviderImpl threw
expected exception at create EntityManagerFactory:
org.apache.openjpa.persistence.PersistenceException<openjpa-1.1.1-SNAPSHOT-
r422266:891341 fatal general error>
org.apache.openjpa.persistence.PersistenceException: There was an error when invoking
the static newInstance method on the named factory class
"kodo.jdbc.kernel.KodoJDBCBrokerFactory".
Please help!
Did you declare a "provider" element within your "persistence-unit" element in persistence.xml? It should look something like this:
<persistence-unit name="Draco-PU">
<provider>org.apache.openjpa.persistence.PersistenceProviderImpl</provider>
</persistence-unit>
Create the next structure inside your WEB-INF folder: classes/META-INF, put your persistence.xml file in and restart the server.
Weblogic looks for the file in the build directory.