AMashenkov commented on code in PR #1134:
URL: https://github.com/apache/ignite-3/pull/1134#discussion_r999180353


##########
modules/schema/src/main/java/org/apache/ignite/internal/schema/SchemaManager.java:
##########
@@ -400,15 +450,83 @@ public void stop() throws Exception {
     }
 
     /**
-     * Gets a direct accessor for the configuration distributed property.
-     * If the metadata access only locally configured the method will return 
local property accessor.
+     * Gets the latest version of the table schema which available in 
Metastore.
+     *
+     * @param tblId Table id.
+     * @return The latest schema version.
+     */
+    private int latestSchemaVersion(UUID tblId) {
+        try {
+            Cursor<Entry> cur = metastorageMgr.prefix(schemaHistPrefix(tblId));
+
+            int lastVer = INITIAL_SCHEMA_VERSION;
+
+            for (Entry ent : cur) {
+                String key = ent.key().toString();
+                int descVer = extractVerFromSchemaKey(key);
+
+                if (descVer > lastVer) {
+                    lastVer = descVer;
+                }
+            }
+
+            return lastVer;
+        } catch (NodeStoppingException e) {
+            throw new IgniteException(e.traceId(), e.code(), e.getMessage(), 
e);
+        }
+    }
+
+    /**
+     * Collect all schemes for appropriate table.
      *
-     * @param property Distributed configuration property to receive direct 
access.
-     * @param <T> Type of the property accessor.
-     * @return An accessor for distributive property.
-     * @see #getMetadataLocallyOnly
+     * @param tblId Table id.
+     * @return Sorted by key collection of schemes.
+     */
+    private SortedMap<Integer, byte[]> collectAllSchemas(UUID tblId) {
+        try {
+            Cursor<Entry> cur = metastorageMgr.prefix(schemaHistPrefix(tblId));
+
+            SortedMap<Integer, byte[]> schemes = new TreeMap<>();
+
+            for (Entry ent : cur) {
+                String key = ent.key().toString();
+                int descVer = extractVerFromSchemaKey(key);
+
+                schemes.put(descVer, ent.value());
+            }
+
+            return schemes;
+        } catch (NodeStoppingException e) {
+            throw new IgniteException(e.traceId(), e.code(), e.getMessage(), 
e);
+        }
+    }
+
+    private int extractVerFromSchemaKey(String key) {
+        int pos = key.lastIndexOf('.');
+        assert pos != -1 : "Unexpected key: " + key;
+
+        key = key.substring(pos + 1);
+        return Integer.parseInt(key);
+    }
+
+    /**
+     * Forms schema history key.
+     *
+     * @param tblId Table id.
+     * @param ver Schema version.
+     * @return {@link ByteArray} representation.
+     */
+    private static ByteArray schemaWithVerHistKey(UUID tblId, int ver) {
+        return ByteArray.fromString(tblId + SCHEMA_STORE_PREFIX + ver);
+    }
+
+    /**
+     * Forms schema history predicate.

Review Comment:
   ```suggestion
        * Forms schema history item prefix.
   ```



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