korlov42 commented on code in PR #1134:
URL: https://github.com/apache/ignite-3/pull/1134#discussion_r995538990
##########
modules/schema/src/main/java/org/apache/ignite/internal/schema/SchemaManager.java:
##########
@@ -400,15 +452,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) {
Review Comment:
could you please clarify who is throwing this exception?
--
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]