Hi,
Sorry I am not able to share a complete solution. bean xml attached and
code snippet in below
IgniteConfiguration igniteGridIg = new IgniteConfiguration();
igniteGridIg.AutoGenerateIgniteInstanceName = true;
if
(!string.IsNullOrEmpty(GlobalVariables.IgniteSettings.IGNITE_HOME))
{
igniteGridIg.IgniteHome =
GlobalVariables.IgniteSettings.IGNITE_HOME;
}
var gridDetails =
GlobalVariables.IgniteSettings.GridDetails.Where(gd =>
gd.GridType.Equals("DynamicGrid",
StringComparison.OrdinalIgnoreCase)).FirstOrDefault();
//setting ignite working directory if not ignite will run with
default work directory
if
(!string.IsNullOrEmpty(GlobalVariables.IgniteSettings.WorkDirectory))
{
igniteGridIg.WorkDirectory =
Path.Combine(GlobalVariables.IgniteSettings.WorkDirectory,
gridDetails.CacheType);
}
if (null != gridDetails)
{
GridName = gridDetails.GridName;
igniteGridIg.SpringConfigUrl =
Path.Combine(GlobalVariables.IgniteSettings.ConfigurationPath,
gridDetails.SpringXMLFileName);
igniteGridIg.ConsistentId =
Guid.NewGuid().ToString().ToUpper();
ICollection<string> lstJvmOptions = null;
//"IgniteJVMOption": "-XX:+DisableExplicitGC,-XX:+UseG1GC,-Xms1g,-Xmx2g"
if (string.IsNullOrEmpty(gridDetails.IgniteJVMOption))
{
lstJvmOptions =
GlobalVariables.IgniteSettings.IgniteJVMOptionDefault.Split(',').Where(x =>
!string.IsNullOrWhiteSpace(x)).ToList();
}
else
lstJvmOptions =
gridDetails.IgniteJVMOption.Split(',').Where(x =>
!string.IsNullOrWhiteSpace(x)).ToList();
if (lstJvmOptions.Any())
igniteGridIg.JvmOptions = lstJvmOptions;
int RetryCount = 0;
while (InstanceObject == null)
{
try
{
RetryCount++;
//Try to start Ignite
if
(!String.IsNullOrEmpty(ApplicationSettingKeys.Get<string>("IgniteInstanceRetryLimit"))
&& RetryCount >
(ApplicationSettingKeys.Get<int>("IgniteInstanceRetryLimit")))
{
break;
}
//Try to start Ignite
if
(String.IsNullOrEmpty(ApplicationSettingKeys.Get<string>("IgniteDynamicCacheGrid")))
InstanceObject = Ignition.Start(igniteGridIg);
else
InstanceObject =
Ignition.TryGetIgnite(ApplicationSettingKeys.Get<string>("IgniteDynamicCacheGrid"))
?? Ignition.Start(igniteGridIg);
}
catch (Exception ex) //If failing to start Ignite, wait
a bit for the previous AppDomain to stop the Ignite running instance...
{
logContextInfo.ErrorLogger(ex);
}
}
public ICache<string, testModel> testModelICache { get; set; }
using (new Log4NetTimeLogHelper(logContextInfo, "testModelModel",
"testModelModel"))
{
testModelICache = testModelICache ??
InstanceObject.GetCache<string, testModelModel>("testModelModel")
.WithExpiryPolicy(new ExpiryPolicy(
TimeSpan.FromMinutes(GlobalVariables.testModelExpiryTime),
TimeSpan.FromMinutes(GlobalVariables.testModelExpiryTime),
TimeSpan.FromMinutes(GlobalVariables.testModelExpiryTime)
));
}
public CacheServiceResponse GetCacheById(string Key)
{
CacheServiceResponse response = new CacheServiceResponse();
var model = (T)Activator.CreateInstance(typeof(T));
try
{
IgniteCache.TryGet(Key, out var value);
var k = IgniteCache.TryGetAsync(Key);
if (null != value)
{
model = (T)value;
response.SingleObject = model;
response.Status = true;
response.StatusCode = System.Net.HttpStatusCode.OK;
}
else
{
response.Status = false;
response.Message = "Given key " + Key + " not
present in the cache.";
response.StatusCode =
System.Net.HttpStatusCode.NoContent;
}
}cache(exception ex)
{
}
}
Regards,
Charlin
On Fri, 16 Sept 2022 at 18:22, Pavel Tupitsyn <[email protected]> wrote:
> Can you share a reproducer?
>
> On Fri, Sep 16, 2022 at 3:13 PM Charlin S <[email protected]> wrote:
>
>> Hi,
>> Data loss is not possible, because some other time I am able to read data
>> with the same key.
>>
>> FYI: data update not in our workflow(Please ignore my previous mail
>> statement it is possible to update the cache by another process/workflow).
>> Always data read only once cache inserted by key.
>>
>> Regards,
>> Charlin
>>
>>
>> On Fri, 16 Sept 2022 at 17:21, Pavel Tupitsyn <[email protected]>
>> wrote:
>>
>>> Ok, so the issue is that the key is not present in the cache, and this
>>> is not expected.
>>> Data loss is possible if one of Ignite nodes goes down, and backups [1]
>>> are not configured.
>>> Please check server logs for errors.
>>>
>>> [1]
>>> https://ignite.apache.org/docs/latest/configuring-caches/configuring-backups
>>>
>>> On Fri, Sep 16, 2022 at 2:38 PM Charlin S <[email protected]>
>>> wrote:
>>>
>>>> Hi,
>>>> There is no exception and executing the else part. it is possible to
>>>> update the cache by another process/workflow.
>>>> //response is custom class object
>>>> var model = (T)Activator.CreateInstance(typeof(T));
>>>> IgniteCache.TryGet(Key, out var value);
>>>> if (null != value)
>>>> {
>>>> model = (T)value;
>>>> response.SingleObject = model;
>>>> response.Status = true;
>>>> response.StatusCode =
>>>> System.Net.HttpStatusCode.OK;
>>>> }
>>>> else
>>>> {
>>>> response.Status = false;
>>>> response.Message = "Given key " + Key + " not
>>>> present in the cache.";
>>>> response.StatusCode =
>>>> System.Net.HttpStatusCode.NoContent;
>>>> }
>>>>
>>>> Regards,
>>>> Charlin
>>>>
>>>> On Fri, 16 Sept 2022 at 16:53, Pavel Tupitsyn <[email protected]>
>>>> wrote:
>>>>
>>>>> Hi Charlin,
>>>>>
>>>>> Please provide full exception details.
>>>>>
>>>>> On Fri, Sep 16, 2022 at 2:04 PM Charlin S <[email protected]>
>>>>> wrote:
>>>>>
>>>>>> Hi All,
>>>>>> Cache.TryGet failed to read intermittently and was unable to read
>>>>>> some time later.
>>>>>>
>>>>>> having 3 server nodes and 11 client nodes. cache mode is partition
>>>>>> and atomicitymode not been set.
>>>>>>
>>>>>> Regards,
>>>>>> Charlin
>>>>>>
>>>>>>
<?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:util="http://www.springframework.org/schema/util"
xsi:schemaLocation="http://www.springframework.org/schema/beans
http://www.springframework.org/schema/beans/spring-beans.xsd
http://www.springframework.org/schema/util
http://www.springframework.org/schema/util/spring-util.xsd">
<bean class="org.apache.ignite.configuration.IgniteConfiguration">
<property name="clientMode" value="false"/>
<property name="clientFailureDetectionTimeout" value="120000"/>
<property name="igniteInstanceName" value="testgrid"/>
<property name="longQueryWarningTimeout" value="4000"/>
<property name="failureDetectionTimeout" value="120000"/>
<property name="localHost" value="10.201.30.116"/>
<property name="segmentationPolicy" value="RESTART_JVM"/>
<property name="segmentCheckFrequency" value="20000"/>
<property name="segmentationResolveAttempts" value="10"/>
<property name="discoverySpi">
<bean class="org.apache.ignite.spi.discovery.tcp.TcpDiscoverySpi">
<property name="localPort" value="57800"/>
<property name="ipFinder">
<bean class="org.apache.ignite.spi.discovery.tcp.ipfinder.vm.TcpDiscoveryVmIpFinder">
<property name="addresses">
<list>
<value>10.201.30.116:57800</value>
<value>10.201.30.117:57800</value>
<value>10.201.30.115:57800</value>
</list>
</property>
</bean>
</property>
</bean>
</property>
<property name="dataStorageConfiguration">
<bean class="org.apache.ignite.configuration.DataStorageConfiguration">
<property name="defaultDataRegionConfiguration">
<bean class="org.apache.ignite.configuration.DataRegionConfiguration">
<property name="name" value="testgrid_Data_Region"/>
<property name="initialSize" value="#{1L * 1024 * 1024 * 1024}"/>
<property name="maxSize" value="#{5L * 1024 * 1024 * 1024}"/>
</bean>
</property>
</bean>
</property>
<property name="communicationSpi">
<bean class="org.apache.ignite.spi.communication.tcp.TcpCommunicationSpi">
<property name="sharedMemoryPort" value="-1"/>
<property name="localPort" value="57905"/>
</bean>
</property>
</bean>
</beans><?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:util="http://www.springframework.org/schema/util"
xsi:schemaLocation="http://www.springframework.org/schema/beans
http://www.springframework.org/schema/beans/spring-beans.xsd
http://www.springframework.org/schema/util
http://www.springframework.org/schema/util/spring-util.xsd">
<bean class="org.apache.ignite.configuration.IgniteConfiguration">
<property name="clientMode" value="true"/>
<property name="clientFailureDetectionTimeout" value="120000"/>
<property name="igniteInstanceName" value="testgrid"/>
<property name="longQueryWarningTimeout" value="4000"/>
<property name="failureDetectionTimeout" value="120000"/>
<property name="localHost" value="10.201.11.10"/>
<property name="segmentationPolicy" value="RESTART_JVM"/>
<property name="segmentCheckFrequency" value="20000"/>
<property name="segmentationResolveAttempts" value="10"/>
<property name="discoverySpi">
<bean class="org.apache.ignite.spi.discovery.tcp.TcpDiscoverySpi">
<property name="localPort" value="57800"/>
<property name="ipFinder">
<bean class="org.apache.ignite.spi.discovery.tcp.ipfinder.vm.TcpDiscoveryVmIpFinder">
<property name="addresses">
<list>
<value>10.201.30.116:57800</value>
<value>10.201.30.117:57800</value>
<value>10.201.30.115:57800</value>
</list>
</property>
</bean>
</property>
</bean>
</property>
<property name="communicationSpi">
<bean class="org.apache.ignite.spi.communication.tcp.TcpCommunicationSpi">
<property name="sharedMemoryPort" value="-1"/>
<property name="localPort" value="57905"/>
</bean>
</property>
</bean>
</beans>