AMashenkov commented on code in PR #1134:
URL: https://github.com/apache/ignite-3/pull/1134#discussion_r996905539
##########
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(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 (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(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 (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.
+ */
+ private 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);
+ private static ByteArray schemaHistPredicate(UUID tblId) {
Review Comment:
```suggestion
private static ByteArray schemaHistoryPrefix(UUID tblId) {
```
--
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]