Copilot commented on code in PR #7414:
URL: https://github.com/apache/ignite-3/pull/7414#discussion_r2693644268


##########
modules/platforms/dotnet/Apache.Extensions.Caching.Ignite/IgniteDistributedCache.cs:
##########
@@ -58,12 +55,11 @@ public sealed class IgniteDistributedCache : 
IDistributedCache, IDisposable
     public IgniteDistributedCache(
         IOptions<IgniteDistributedCacheOptions> optionsAccessor,
         IServiceProvider serviceProvider)
+        : this(
+            options: optionsAccessor.Value,
+            igniteClientGroup: 
serviceProvider.GetRequiredKeyedService<IgniteClientGroup>(optionsAccessor.Value.IgniteClientGroupServiceKey))

Review Comment:
   The argument null validation has been removed from this constructor, but 
optionsAccessor could still be null. The call to optionsAccessor.Value on line 
59 will throw a NullReferenceException instead of the more descriptive 
ArgumentNullException. Add ArgumentNullException.ThrowIfNull(optionsAccessor) 
and ArgumentNullException.ThrowIfNull(serviceProvider) before the constructor 
chain.



##########
modules/platforms/dotnet/Apache.Extensions.Caching.Ignite/Internal/CacheEntryMapper.cs:
##########
@@ -0,0 +1,94 @@
+/*
+ * Licensed to the Apache Software Foundation (ASF) under one or more
+ * contributor license agreements. See the NOTICE file distributed with
+ * this work for additional information regarding copyright ownership.
+ * The ASF licenses this file to You under the Apache License, Version 2.0
+ * (the "License"); you may not use this file except in compliance with
+ * the License. You may obtain a copy of the License at
+ *
+ *      http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ */
+
+namespace Apache.Extensions.Caching.Ignite.Internal;
+
+using Apache.Ignite.Table.Mapper;
+
+/// <summary>
+/// Cache entry mapper.
+/// </summary>
+internal sealed class CacheEntryMapper : IMapper<KeyValuePair<string, 
CacheEntry>>
+{
+    private readonly IgniteDistributedCacheOptions _options;
+
+    /// <summary>
+    /// Initializes a new instance of the <see cref="CacheEntryMapper"/> class.
+    /// </summary>
+    /// <param name="options">Options.</param>
+    public CacheEntryMapper(IgniteDistributedCacheOptions options) => _options 
= options;
+
+    /// <inheritdoc/>
+    public void Write(KeyValuePair<string, CacheEntry> obj, ref RowWriter 
rowWriter, IMapperSchema schema)
+    {
+        foreach (var column in schema.Columns)
+        {
+            if (column.Name == _options.KeyColumnName)
+            {
+                rowWriter.WriteString(_options.CacheKeyPrefix + obj.Key);
+            }
+            else if (column.Name == _options.ValueColumnName)
+            {
+                rowWriter.WriteBytes(obj.Value.Value);
+            }
+            else
+            {
+                rowWriter.Skip();
+            }
+        }
+    }
+
+    /// <inheritdoc/>
+    public KeyValuePair<string, CacheEntry> Read(ref RowReader rowReader, 
IMapperSchema schema)
+    {
+        string? key = null;
+        byte[]? value = null;
+
+        foreach (var column in schema.Columns)
+        {
+            if (column.Name == _options.KeyColumnName)
+            {
+                key = rowReader.ReadString();
+            }
+            else if (column.Name == _options.ValueColumnName)
+            {
+                value = rowReader.ReadBytes();
+            }
+            else
+            {
+                rowReader.Skip();
+            }
+        }
+
+        if (key == null)
+        {
+            throw new InvalidOperationException("Key column is missing.");
+        }
+
+        if (value == null)
+        {
+            throw new InvalidOperationException("Value column is missing.");
+        }
+
+        if (_options.CacheKeyPrefix is { } prefix && key.StartsWith(prefix, 
StringComparison.Ordinal))
+        {
+            key = key[prefix.Length..];

Review Comment:
   The prefix removal logic should validate that the key actually starts with 
the prefix before attempting to strip it. If a key in the database doesn't have 
the expected prefix (which could happen with an existing table), this will 
silently skip the prefix removal, potentially causing confusion. Consider 
logging a warning or throwing an exception if the prefix is configured but not 
found in the key read from the database.
   ```suggestion
           if (_options.CacheKeyPrefix is { } prefix)
           {
               if (key.StartsWith(prefix, StringComparison.Ordinal))
               {
                   key = key[prefix.Length..];
               }
               else
               {
                   throw new InvalidOperationException(
                       $"Cache key '{key}' does not start with the expected 
prefix '{prefix}'.");
               }
   ```



##########
modules/platforms/dotnet/Apache.Extensions.Caching.Ignite/IgniteDistributedCache.cs:
##########
@@ -92,18 +89,9 @@ public IgniteDistributedCache(
         ArgumentNullException.ThrowIfNull(key);
 
         var view = await GetViewAsync().ConfigureAwait(false);
-        var tuple = GetKey(key);
-
-        try
-        {
-            var (val, hasVal) = await view.GetAsync(null, 
tuple).ConfigureAwait(false);
 
-            return hasVal ? (byte[]?)val[_options.ValueColumnName] : null;
-        }
-        finally
-        {
-            _tuplePool.Return(tuple);
-        }
+        (CacheEntry val, bool hasVal) = await view.GetAsync(null, 
key).ConfigureAwait(false);
+        return hasVal ? val.Value : null;

Review Comment:
   The GetAsync method returns an Option<TV> according to the IKeyValueView 
API, not a tuple with bool. This should be using the Option<T> pattern. The 
correct usage would be: `Option<CacheEntry> option = await view.GetAsync(null, 
key).ConfigureAwait(false); return option.HasValue ? option.Value.Value : null;`
   ```suggestion
           var option = await view.GetAsync(null, key).ConfigureAwait(false);
           return option.HasValue ? option.Value.Value : null;
   ```



-- 
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.

To unsubscribe, e-mail: [email protected]

For queries about this service, please contact Infrastructure at:
[email protected]

Reply via email to