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


##########
modules/schema/src/main/java/org/apache/ignite/internal/schema/SchemaManager.java:
##########
@@ -400,15 +453,128 @@ 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 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 The latest schema version.
+     */
+    private int latestSchemaVersion(UUID tblId) {
+        try {
+            Cursor<Entry> cur = 
metastorageMgr.prefix(schemaHistPredicate(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 (NoSuchElementException e) {
+            assert false : "Table must exist. [tableId=" + tblId + ']';
+
+            return INITIAL_SCHEMA_VERSION;
+        } catch (NodeStoppingException e) {
+            throw new IgniteException(e.traceId(), e.code(), e.getMessage(), 
e);
+        }
+    }
+
+    /**
+     * Collect all schemes for appropriate table.
+     *
+     * @param tblId Table id.
+     * @return Sorted by key collection of schemes.
+     */
+    private SortedMap<Integer, byte[]> collectAllSchemas(UUID tblId) {
+        try {
+            Cursor<Entry> cur = 
metastorageMgr.prefix(schemaHistPredicate(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 (NoSuchElementException e) {
+            assert false : "Table must exist. [tableId=" + tblId + ']';
+
+            return Collections.emptySortedMap();
+        } catch (NodeStoppingException e) {
+            throw new IgniteException(e.traceId(), e.code(), e.getMessage(), 
e);
+        }
+    }
+
+    /**
+     * Gets the latest serialized schema of the table which available in 
Metastore.
+     *
+     * @param tblId Table id.
+     * @return The latest schema version or {@code null} if not found.
+     */
+    private @Nullable byte[] schemaById(UUID tblId, int ver) {
+        try {
+            Cursor<Entry> cur = 
metastorageMgr.prefix(schemaHistPredicate(tblId));
+
+            int lastVer = INITIAL_SCHEMA_VERSION;
+            byte[] schema = null;
+
+            for (Entry ent : cur) {
+                String key = ent.key().toString();
+                int descVer = extractVerFromSchemaKey(key);
+
+                if (ver != -1) {
+                    if (ver == descVer) {
+                        return ent.value();
+                    }
+                } else if (descVer >= lastVer) {
+                    lastVer = descVer;
+                    schema = ent.value();
+                }
+            }
+
+            return schema;
+        } catch (NoSuchElementException e) {
+            assert false : "Table must exist. [tableId=" + tblId + ']';
+
+            return null;
+        } catch (NodeStoppingException e) {
+            throw new IgniteException(e.traceId(), e.code(), e.getMessage(), 
e);
+        }
+    }
+
+    private int extractVerFromSchemaKey(String key) {
+        int pos = key.indexOf(':');
+        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.
+     */
+    public static ByteArray schemaWithVerHistKey(UUID tblId, int ver) {

Review Comment:
   looks like it may be private



##########
modules/schema/src/main/java/org/apache/ignite/internal/schema/SchemaManager.java:
##########
@@ -400,15 +453,128 @@ 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 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 The latest schema version.
+     */
+    private int latestSchemaVersion(UUID tblId) {
+        try {
+            Cursor<Entry> cur = 
metastorageMgr.prefix(schemaHistPredicate(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 (NoSuchElementException e) {
+            assert false : "Table must exist. [tableId=" + tblId + ']';
+
+            return INITIAL_SCHEMA_VERSION;
+        } catch (NodeStoppingException e) {
+            throw new IgniteException(e.traceId(), e.code(), e.getMessage(), 
e);
+        }
+    }
+
+    /**
+     * Collect all schemes for appropriate table.
+     *
+     * @param tblId Table id.
+     * @return Sorted by key collection of schemes.
+     */
+    private SortedMap<Integer, byte[]> collectAllSchemas(UUID tblId) {
+        try {
+            Cursor<Entry> cur = 
metastorageMgr.prefix(schemaHistPredicate(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 (NoSuchElementException e) {
+            assert false : "Table must exist. [tableId=" + tblId + ']';
+
+            return Collections.emptySortedMap();
+        } catch (NodeStoppingException e) {
+            throw new IgniteException(e.traceId(), e.code(), e.getMessage(), 
e);
+        }
+    }
+
+    /**
+     * Gets the latest serialized schema of the table which available in 
Metastore.
+     *
+     * @param tblId Table id.
+     * @return The latest schema version or {@code null} if not found.
+     */
+    private @Nullable byte[] schemaById(UUID tblId, int ver) {
+        try {
+            Cursor<Entry> cur = 
metastorageMgr.prefix(schemaHistPredicate(tblId));
+
+            int lastVer = INITIAL_SCHEMA_VERSION;
+            byte[] schema = null;
+
+            for (Entry ent : cur) {
+                String key = ent.key().toString();
+                int descVer = extractVerFromSchemaKey(key);
+
+                if (ver != -1) {
+                    if (ver == descVer) {
+                        return ent.value();
+                    }
+                } else if (descVer >= lastVer) {
+                    lastVer = descVer;
+                    schema = ent.value();
+                }
+            }
+
+            return schema;
+        } catch (NoSuchElementException e) {
+            assert false : "Table must exist. [tableId=" + tblId + ']';
+
+            return null;
+        } catch (NodeStoppingException e) {
+            throw new IgniteException(e.traceId(), e.code(), e.getMessage(), 
e);
+        }
+    }
+
+    private int extractVerFromSchemaKey(String key) {
+        int pos = key.indexOf(':');
+        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.
+     */
+    public static ByteArray schemaWithVerHistKey(UUID tblId, int ver) {
+        return ByteArray.fromString(tblId + SCHEMA_STORE_PREDICATE + ver);
+    }
+
+    /**
+     * Forms schema history predicate.
+     *
+     * @param tblId Table id.
+     * @return {@link ByteArray} representation.
      */
-    private <T extends ConfigurationProperty<?>> T directProxy(T property) {
-        return getMetadataLocallyOnly ? property : 
ConfigurationUtil.directProxy(property);
+    public static ByteArray schemaHistPredicate(UUID tblId) {

Review Comment:
   looks like it may be private



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