You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@amoro.apache.org by "baiyangtx (via GitHub)" <gi...@apache.org> on 2025/08/23 17:27:36 UTC

[PR] [AMORO-3747] Introducing a more general TableRuntime storage structure [amoro]

baiyangtx opened a new pull request, #3748:
URL: https://github.com/apache/amoro/pull/3748

   
   
   ## Why are the changes needed?
   
   
   Close #3747.
   
   ## Brief change log
   
   -
   
   ## How was this patch tested?
   
   - [ ] Add some test cases that check the changes thoroughly including negative and positive cases if possible
   
   - [ ] Add screenshots for manual tests if appropriate
   
   - [ ] Run test locally before making a pull request
   
   ## Documentation
   
   - Does this pull request introduce a new feature? (yes / no)
   - If yes, how is the feature documented? (not applicable / docs / JavaDocs / not documented)
   


-- 
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: commits-unsubscribe@amoro.apache.org

For queries about this service, please contact Infrastructure at:
users@infra.apache.org


Re: [PR] [AMORO-3747] Introducing a more general TableRuntime storage structure [amoro]

Posted by "baiyangtx (via GitHub)" <gi...@apache.org>.
baiyangtx commented on code in PR #3748:
URL: https://github.com/apache/amoro/pull/3748#discussion_r2299565960


##########
amoro-ams/src/main/java/org/apache/amoro/server/table/DefaultTableRuntimeStore.java:
##########
@@ -0,0 +1,282 @@
+/*
+ * 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.
+ */
+
+package org.apache.amoro.server.table;
+
+import org.apache.amoro.ServerTableIdentifier;
+import org.apache.amoro.exception.AmoroRuntimeException;
+import org.apache.amoro.exception.PersistenceException;
+import org.apache.amoro.server.persistence.NestedSqlSession;
+import org.apache.amoro.server.persistence.PersistentBase;
+import org.apache.amoro.server.persistence.TableRuntimeMeta;
+import org.apache.amoro.server.persistence.TableRuntimeState;
+import org.apache.amoro.server.persistence.mapper.TableMetaMapper;
+import org.apache.amoro.server.persistence.mapper.TableRuntimeMapper;
+import org.apache.amoro.shade.guava32.com.google.common.base.Preconditions;
+import org.apache.amoro.shade.guava32.com.google.common.collect.Lists;
+import org.apache.amoro.shade.guava32.com.google.common.collect.Sets;
+import org.apache.amoro.table.StateKey;
+import org.apache.amoro.table.TableRuntimeStore;
+import org.apache.amoro.table.TableSummary;
+import org.slf4j.Logger;
+import org.slf4j.LoggerFactory;
+
+import java.util.List;
+import java.util.Map;
+import java.util.Set;
+import java.util.concurrent.ConcurrentHashMap;
+import java.util.concurrent.locks.Lock;
+import java.util.concurrent.locks.ReentrantLock;
+import java.util.function.Consumer;
+import java.util.function.Function;
+import java.util.stream.Collectors;
+
+public class DefaultTableRuntimeStore extends PersistentBase implements TableRuntimeStore {
+  private static final Logger LOG = LoggerFactory.getLogger(DefaultTableRuntimeStore.class);
+  private final Lock tableLock = new ReentrantLock();
+  private final ServerTableIdentifier tableIdentifier;
+  private final TableRuntimeMeta meta;
+  private final Map<String, TableRuntimeState> states = new ConcurrentHashMap<>();
+
+  public DefaultTableRuntimeStore(
+      ServerTableIdentifier tableIdentifier,
+      TableRuntimeMeta meta,
+      List<StateKey<?>> requiredStates,
+      List<TableRuntimeState> restoredStates) {
+    Preconditions.checkNotNull(tableIdentifier, "ServerTableIdentifier must not be null.");
+    Preconditions.checkNotNull(meta, "TableRuntimeMeta must not be null.");
+    Preconditions.checkNotNull(requiredStates, "requiredStates must not be null.");
+    Preconditions.checkNotNull(restoredStates, "restoredStates must not be null.");
+    this.tableIdentifier = tableIdentifier;
+    this.meta = meta;
+    restoreStates(requiredStates, restoredStates);
+  }
+
+  @Override
+  public ServerTableIdentifier getTableIdentifier() {
+    return tableIdentifier;
+  }
+
+  @Override
+  public String getGroupName() {
+    return this.meta.getGroupName();
+  }
+
+  @Override
+  public Map<String, String> getTableConfig() {
+    return this.meta.getTableConfig();
+  }
+
+  @Override
+  public int getStatusCode() {
+    return this.meta.getStatusCode();
+  }
+
+  @Override
+  public <T> T getState(StateKey<T> key) {
+    Preconditions.checkNotNull(key, "TableRuntime state key cannot be null");
+    Preconditions.checkNotNull(
+        states.containsKey(key.getKey()), "TableRuntime state %s not initialized", key);
+    TableRuntimeState tableState = states.get(key.getKey());
+    return key.deserialize(tableState.getStateValue());
+  }
+
+  @Override
+  public void synchronizedInvoke(Runnable runnable) {
+    tableLock.lock();
+    try {
+      runnable.run();
+    } finally {
+      tableLock.unlock();
+    }
+  }
+
+  @Override
+  public void dispose() {
+    doAsTransaction(
+        () -> doAs(TableRuntimeMapper.class, m -> m.deleteRuntime(tableIdentifier.getId())),
+        () -> doAs(TableRuntimeMapper.class, m -> m.removeAllTableStates(tableIdentifier.getId())),
+        () -> doAs(TableMetaMapper.class, m -> m.deleteTableIdById(tableIdentifier.getId())));
+  }
+
+  @Override
+  public TableRuntimeOperation begin() {
+    return new TableRuntimeOperationImpl();
+  }
+
+  protected void restoreStates(
+      List<StateKey<?>> requiredStates, List<TableRuntimeState> restoredStates) {
+    Map<String, TableRuntimeState> stateMap =
+        restoredStates.stream()
+            .collect(Collectors.toMap(TableRuntimeState::getStateKey, Function.identity()));
+
+    requiredStates.forEach(
+        key -> {
+          if (stateMap.containsKey(key.getKey())) {
+            states.put(key.getKey(), stateMap.get(key.getKey()));
+            stateMap.remove(key.getKey());
+          } else {
+            doAs(
+                TableRuntimeMapper.class,
+                mapper ->
+                    mapper.saveState(
+                        tableIdentifier.getId(), key.getKey(), key.serializeDefault()));
+            TableRuntimeState state =
+                getAs(
+                    TableRuntimeMapper.class,
+                    m -> m.getState(tableIdentifier.getId(), key.getKey()));
+            Preconditions.checkNotNull(state, "State %s initialize failed", key.getKey());
+            states.put(key.getKey(), state);
+          }
+        });
+
+    if (!stateMap.isEmpty()) {
+      LOG.warn("Found {} useless runtime states for {}", stateMap.size(), tableIdentifier);
+      stateMap.forEach(
+          (k, s) -> {
+            LOG.warn("Remove useless runtime state {} for {}", k, tableIdentifier);
+            doAs(TableRuntimeMapper.class, m -> m.removeState(s.getStateId()));
+          });
+    }
+  }
+
+  private class TableRuntimeOperationImpl implements TableRuntimeOperation {
+
+    private final TableRuntimeMeta oldMeta;
+    private final List<Runnable> opeartions = Lists.newArrayList();

Review Comment:
   tks, I have fix it.



-- 
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: commits-unsubscribe@amoro.apache.org

For queries about this service, please contact Infrastructure at:
users@infra.apache.org


Re: [PR] [AMORO-3747] Introducing a more general TableRuntime storage structure [amoro]

Posted by "xxubai (via GitHub)" <gi...@apache.org>.
xxubai commented on code in PR #3748:
URL: https://github.com/apache/amoro/pull/3748#discussion_r2298040007


##########
amoro-ams/src/main/java/org/apache/amoro/server/table/AbstractTableRuntime.java:
##########
@@ -0,0 +1,99 @@
+/*
+ * 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.
+ */
+
+package org.apache.amoro.server.table;
+
+import org.apache.amoro.Action;
+import org.apache.amoro.ServerTableIdentifier;
+import org.apache.amoro.SupportsProcessPlugins;
+import org.apache.amoro.TableFormat;
+import org.apache.amoro.TableRuntime;
+import org.apache.amoro.config.TableConfiguration;
+import org.apache.amoro.process.AmoroProcess;
+import org.apache.amoro.process.ProcessFactory;
+import org.apache.amoro.process.TableProcessState;
+import org.apache.amoro.server.persistence.PersistentBase;
+import org.apache.amoro.table.TableRuntimeStore;
+
+import java.util.List;
+
+public abstract class AbstractTableRuntime extends PersistentBase
+    implements TableRuntime, SupportsProcessPlugins {
+
+  private final TableRuntimeStore store;
+
+  protected AbstractTableRuntime(TableRuntimeStore store) {
+    this.store = store;
+  }
+
+  public TableRuntimeStore store() {
+    return store;
+  }
+
+  @Override
+  public ServerTableIdentifier getTableIdentifier() {
+    return store().getTableIdentifier();
+  }
+
+  @Override
+  public TableConfiguration getTableConfiguration() {
+    return TableConfigurations.parseTableConfig(store().getTableConfig());
+  }
+
+  @Override
+  public TableFormat getFormat() {

Review Comment:
   getFormat already has default impelementation



##########
amoro-ams/src/main/java/org/apache/amoro/server/dashboard/controller/TableController.java:
##########
@@ -685,11 +686,6 @@ public void cancelOptimizingProcess(Context ctx) {
     ServerTableIdentifier serverTableIdentifier =

Review Comment:
   This can be also removed if don't check the processId



##########
amoro-ams/src/main/java/org/apache/amoro/server/table/DefaultTableRuntimeStore.java:
##########
@@ -0,0 +1,282 @@
+/*
+ * 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.
+ */
+
+package org.apache.amoro.server.table;
+
+import org.apache.amoro.ServerTableIdentifier;
+import org.apache.amoro.exception.AmoroRuntimeException;
+import org.apache.amoro.exception.PersistenceException;
+import org.apache.amoro.server.persistence.NestedSqlSession;
+import org.apache.amoro.server.persistence.PersistentBase;
+import org.apache.amoro.server.persistence.TableRuntimeMeta;
+import org.apache.amoro.server.persistence.TableRuntimeState;
+import org.apache.amoro.server.persistence.mapper.TableMetaMapper;
+import org.apache.amoro.server.persistence.mapper.TableRuntimeMapper;
+import org.apache.amoro.shade.guava32.com.google.common.base.Preconditions;
+import org.apache.amoro.shade.guava32.com.google.common.collect.Lists;
+import org.apache.amoro.shade.guava32.com.google.common.collect.Sets;
+import org.apache.amoro.table.StateKey;
+import org.apache.amoro.table.TableRuntimeStore;
+import org.apache.amoro.table.TableSummary;
+import org.slf4j.Logger;
+import org.slf4j.LoggerFactory;
+
+import java.util.List;
+import java.util.Map;
+import java.util.Set;
+import java.util.concurrent.ConcurrentHashMap;
+import java.util.concurrent.locks.Lock;
+import java.util.concurrent.locks.ReentrantLock;
+import java.util.function.Consumer;
+import java.util.function.Function;
+import java.util.stream.Collectors;
+
+public class DefaultTableRuntimeStore extends PersistentBase implements TableRuntimeStore {
+  private static final Logger LOG = LoggerFactory.getLogger(DefaultTableRuntimeStore.class);
+  private final Lock tableLock = new ReentrantLock();
+  private final ServerTableIdentifier tableIdentifier;
+  private final TableRuntimeMeta meta;
+  private final Map<String, TableRuntimeState> states = new ConcurrentHashMap<>();
+
+  public DefaultTableRuntimeStore(
+      ServerTableIdentifier tableIdentifier,
+      TableRuntimeMeta meta,
+      List<StateKey<?>> requiredStates,
+      List<TableRuntimeState> restoredStates) {
+    Preconditions.checkNotNull(tableIdentifier, "ServerTableIdentifier must not be null.");
+    Preconditions.checkNotNull(meta, "TableRuntimeMeta must not be null.");
+    Preconditions.checkNotNull(requiredStates, "requiredStates must not be null.");
+    Preconditions.checkNotNull(restoredStates, "restoredStates must not be null.");
+    this.tableIdentifier = tableIdentifier;
+    this.meta = meta;
+    restoreStates(requiredStates, restoredStates);
+  }
+
+  @Override
+  public ServerTableIdentifier getTableIdentifier() {
+    return tableIdentifier;
+  }
+
+  @Override
+  public String getGroupName() {
+    return this.meta.getGroupName();
+  }
+
+  @Override
+  public Map<String, String> getTableConfig() {
+    return this.meta.getTableConfig();
+  }
+
+  @Override
+  public int getStatusCode() {
+    return this.meta.getStatusCode();
+  }
+
+  @Override
+  public <T> T getState(StateKey<T> key) {
+    Preconditions.checkNotNull(key, "TableRuntime state key cannot be null");
+    Preconditions.checkNotNull(
+        states.containsKey(key.getKey()), "TableRuntime state %s not initialized", key);
+    TableRuntimeState tableState = states.get(key.getKey());
+    return key.deserialize(tableState.getStateValue());
+  }
+
+  @Override
+  public void synchronizedInvoke(Runnable runnable) {
+    tableLock.lock();
+    try {
+      runnable.run();
+    } finally {
+      tableLock.unlock();
+    }
+  }
+
+  @Override
+  public void dispose() {
+    doAsTransaction(
+        () -> doAs(TableRuntimeMapper.class, m -> m.deleteRuntime(tableIdentifier.getId())),
+        () -> doAs(TableRuntimeMapper.class, m -> m.removeAllTableStates(tableIdentifier.getId())),
+        () -> doAs(TableMetaMapper.class, m -> m.deleteTableIdById(tableIdentifier.getId())));
+  }
+
+  @Override
+  public TableRuntimeOperation begin() {
+    return new TableRuntimeOperationImpl();
+  }
+
+  protected void restoreStates(
+      List<StateKey<?>> requiredStates, List<TableRuntimeState> restoredStates) {
+    Map<String, TableRuntimeState> stateMap =
+        restoredStates.stream()
+            .collect(Collectors.toMap(TableRuntimeState::getStateKey, Function.identity()));
+
+    requiredStates.forEach(
+        key -> {
+          if (stateMap.containsKey(key.getKey())) {
+            states.put(key.getKey(), stateMap.get(key.getKey()));
+            stateMap.remove(key.getKey());
+          } else {
+            doAs(
+                TableRuntimeMapper.class,
+                mapper ->
+                    mapper.saveState(
+                        tableIdentifier.getId(), key.getKey(), key.serializeDefault()));
+            TableRuntimeState state =
+                getAs(
+                    TableRuntimeMapper.class,
+                    m -> m.getState(tableIdentifier.getId(), key.getKey()));
+            Preconditions.checkNotNull(state, "State %s initialize failed", key.getKey());
+            states.put(key.getKey(), state);
+          }
+        });
+
+    if (!stateMap.isEmpty()) {
+      LOG.warn("Found {} useless runtime states for {}", stateMap.size(), tableIdentifier);
+      stateMap.forEach(
+          (k, s) -> {
+            LOG.warn("Remove useless runtime state {} for {}", k, tableIdentifier);
+            doAs(TableRuntimeMapper.class, m -> m.removeState(s.getStateId()));
+          });
+    }
+  }
+
+  private class TableRuntimeOperationImpl implements TableRuntimeOperation {
+
+    private final TableRuntimeMeta oldMeta;
+    private final List<Runnable> opeartions = Lists.newArrayList();

Review Comment:
   nit
   ```suggestion
       private final List<Runnable> operations = Lists.newArrayList();
   ```



##########
amoro-ams/src/main/java/org/apache/amoro/server/table/AbstractTableRuntime.java:
##########
@@ -0,0 +1,99 @@
+/*
+ * 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.
+ */
+
+package org.apache.amoro.server.table;
+
+import org.apache.amoro.Action;
+import org.apache.amoro.ServerTableIdentifier;
+import org.apache.amoro.SupportsProcessPlugins;
+import org.apache.amoro.TableFormat;
+import org.apache.amoro.TableRuntime;
+import org.apache.amoro.config.TableConfiguration;
+import org.apache.amoro.process.AmoroProcess;
+import org.apache.amoro.process.ProcessFactory;
+import org.apache.amoro.process.TableProcessState;
+import org.apache.amoro.server.persistence.PersistentBase;
+import org.apache.amoro.table.TableRuntimeStore;
+
+import java.util.List;
+
+public abstract class AbstractTableRuntime extends PersistentBase
+    implements TableRuntime, SupportsProcessPlugins {
+
+  private final TableRuntimeStore store;
+
+  protected AbstractTableRuntime(TableRuntimeStore store) {
+    this.store = store;
+  }
+
+  public TableRuntimeStore store() {
+    return store;
+  }
+
+  @Override
+  public ServerTableIdentifier getTableIdentifier() {
+    return store().getTableIdentifier();
+  }
+
+  @Override
+  public TableConfiguration getTableConfiguration() {
+    return TableConfigurations.parseTableConfig(store().getTableConfig());
+  }
+
+  @Override
+  public TableFormat getFormat() {
+    return store().getTableIdentifier().getFormat();
+  }
+
+  @Override
+  public String getGroupName() {
+    return store().getGroupName();
+  }
+
+  public int getStatusCode() {
+    return store().getStatusCode();
+  }
+
+  @Override
+  public AmoroProcess<? extends TableProcessState> trigger(Action action) {
+    return null;
+  }
+
+  @Override
+  public void install(Action action, ProcessFactory<? extends TableProcessState> processFactory) {}
+
+  @Override
+  public boolean enabled(Action action) {
+    return false;
+  }
+
+  @Override
+  public List<? extends TableProcessState> getProcessStates() {

Review Comment:
   Do not neet to Implement it ?



##########
amoro-ams/src/main/java/org/apache/amoro/server/table/AbstractTableRuntime.java:
##########
@@ -0,0 +1,99 @@
+/*
+ * 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.
+ */
+
+package org.apache.amoro.server.table;
+
+import org.apache.amoro.Action;
+import org.apache.amoro.ServerTableIdentifier;
+import org.apache.amoro.SupportsProcessPlugins;
+import org.apache.amoro.TableFormat;
+import org.apache.amoro.TableRuntime;
+import org.apache.amoro.config.TableConfiguration;
+import org.apache.amoro.process.AmoroProcess;
+import org.apache.amoro.process.ProcessFactory;
+import org.apache.amoro.process.TableProcessState;
+import org.apache.amoro.server.persistence.PersistentBase;
+import org.apache.amoro.table.TableRuntimeStore;
+
+import java.util.List;
+
+public abstract class AbstractTableRuntime extends PersistentBase
+    implements TableRuntime, SupportsProcessPlugins {
+
+  private final TableRuntimeStore store;
+
+  protected AbstractTableRuntime(TableRuntimeStore store) {
+    this.store = store;
+  }
+
+  public TableRuntimeStore store() {
+    return store;
+  }
+
+  @Override
+  public ServerTableIdentifier getTableIdentifier() {
+    return store().getTableIdentifier();
+  }
+
+  @Override
+  public TableConfiguration getTableConfiguration() {
+    return TableConfigurations.parseTableConfig(store().getTableConfig());
+  }
+
+  @Override
+  public TableFormat getFormat() {
+    return store().getTableIdentifier().getFormat();
+  }
+
+  @Override
+  public String getGroupName() {
+    return store().getGroupName();
+  }
+
+  public int getStatusCode() {
+    return store().getStatusCode();
+  }
+
+  @Override
+  public AmoroProcess<? extends TableProcessState> trigger(Action action) {
+    return null;
+  }
+
+  @Override
+  public void install(Action action, ProcessFactory<? extends TableProcessState> processFactory) {}

Review Comment:
   Better to throw an UnsupportException or make it abstract



##########
amoro-ams/src/main/resources/mysql/ams-mysql-init.sql:
##########
@@ -112,28 +112,27 @@ CREATE TABLE `table_metadata`
 CREATE TABLE `table_runtime`
 (
     `table_id`                      bigint(20) NOT NULL,
-    `catalog_name`                  varchar(64) NOT NULL COMMENT 'Catalog name',
-    `db_name`                       varchar(128) NOT NULL COMMENT 'Database name',
-    `table_name`                    varchar(256) NOT NULL COMMENT 'Table name',
-    `current_snapshot_id`           bigint(20) NOT NULL DEFAULT '-1' COMMENT 'Base table current snapshot id',
-    `current_change_snapshotId`     bigint(20) DEFAULT NULL COMMENT 'Change table current snapshot id',
-    `last_optimized_snapshotId`     bigint(20) NOT NULL DEFAULT '-1' COMMENT 'last optimized snapshot id',
-    `last_optimized_change_snapshotId`     bigint(20) NOT NULL DEFAULT '-1' COMMENT 'last optimized change snapshot id',
-    `last_major_optimizing_time`    timestamp NULL DEFAULT NULL COMMENT 'Latest Major Optimize time for all partitions',
-    `last_minor_optimizing_time`    timestamp NULL DEFAULT NULL COMMENT 'Latest Minor Optimize time for all partitions',
-    `last_full_optimizing_time`     timestamp NULL DEFAULT NULL COMMENT 'Latest Full Optimize time for all partitions',
-    `optimizing_status_code`        int DEFAULT 700 COMMENT 'Table optimize status code: 100(FULL_OPTIMIZING), 200(MAJOR_OPTIMIZING), 300(MINOR_OPTIMIZING), 400(COMMITTING), 500(PLANING), 600(PENDING), 700(IDLE)',
-    `optimizing_status_start_time`  timestamp(3) default CURRENT_TIMESTAMP(3) COMMENT 'Table optimize status start time',
-    `optimizing_process_id`         bigint(20) NOT NULL COMMENT 'optimizing_procedure UUID',
-    `optimizer_group`               varchar(64) NOT NULL,
-    `table_config`                  mediumtext,
-    `optimizing_config`             mediumtext,
-    `pending_input`                 mediumtext,
-    `table_summary`                 mediumtext,
+    `group_name`                    varchar(64) NOT NULL,
+    `status_code`                   int DEFAULT 0 NOT NULL COMMENT 'Table runtime status code.',

Review Comment:
   0 status_code makes no sense, do you mean 700(IDLE)?



##########
amoro-ams/src/main/java/org/apache/amoro/server/table/AbstractTableRuntime.java:
##########
@@ -0,0 +1,99 @@
+/*
+ * 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.
+ */
+
+package org.apache.amoro.server.table;
+
+import org.apache.amoro.Action;
+import org.apache.amoro.ServerTableIdentifier;
+import org.apache.amoro.SupportsProcessPlugins;
+import org.apache.amoro.TableFormat;
+import org.apache.amoro.TableRuntime;
+import org.apache.amoro.config.TableConfiguration;
+import org.apache.amoro.process.AmoroProcess;
+import org.apache.amoro.process.ProcessFactory;
+import org.apache.amoro.process.TableProcessState;
+import org.apache.amoro.server.persistence.PersistentBase;
+import org.apache.amoro.table.TableRuntimeStore;
+
+import java.util.List;
+
+public abstract class AbstractTableRuntime extends PersistentBase
+    implements TableRuntime, SupportsProcessPlugins {
+
+  private final TableRuntimeStore store;
+
+  protected AbstractTableRuntime(TableRuntimeStore store) {
+    this.store = store;
+  }
+
+  public TableRuntimeStore store() {
+    return store;
+  }
+
+  @Override
+  public ServerTableIdentifier getTableIdentifier() {
+    return store().getTableIdentifier();
+  }
+
+  @Override
+  public TableConfiguration getTableConfiguration() {
+    return TableConfigurations.parseTableConfig(store().getTableConfig());
+  }
+
+  @Override
+  public TableFormat getFormat() {
+    return store().getTableIdentifier().getFormat();
+  }
+
+  @Override
+  public String getGroupName() {
+    return store().getGroupName();
+  }
+
+  public int getStatusCode() {
+    return store().getStatusCode();
+  }
+
+  @Override
+  public AmoroProcess<? extends TableProcessState> trigger(Action action) {
+    return null;

Review Comment:
   Better to throw an UnsupportException or make it abstract



##########
amoro-ams/src/main/resources/derby/ams-derby-init.sql:
##########
@@ -99,30 +99,33 @@ CREATE TABLE table_metadata (
     CONSTRAINT table_metadata_pk PRIMARY KEY (table_id)
 );
 
+
 CREATE TABLE table_runtime (
-    table_id                    BIGINT NOT NULL,
-    catalog_name                VARCHAR(64) NOT NULL,
-    db_name                     VARCHAR(128) NOT NULL,
-    table_name                  VARCHAR(256) NOT NULL,
-    current_snapshot_id         BIGINT NOT NULL DEFAULT -1,
-    current_change_snapshotId   BIGINT,
-    last_optimized_snapshotId   BIGINT NOT NULL DEFAULT -1,
-    last_optimized_change_snapshotId   BIGINT NOT NULL DEFAULT -1,
-    last_major_optimizing_time  TIMESTAMP,
-    last_minor_optimizing_time  TIMESTAMP,
-    last_full_optimizing_time   TIMESTAMP,
-    optimizing_status_code           INT DEFAULT 700,
-    optimizing_status_start_time TIMESTAMP DEFAULT CURRENT_TIMESTAMP,
-    optimizing_process_id       BIGINT NOT NULL,
-    optimizer_group             VARCHAR(64) NOT NULL,
-    table_config                CLOB(64m),
-    optimizing_config           CLOB(64m),
-    pending_input               CLOB(64m),
-    table_summary               CLOB(64m),
-    CONSTRAINT table_runtime_pk PRIMARY KEY (table_id),
-    CONSTRAINT table_runtime_table_name_idx UNIQUE (catalog_name, db_name, table_name)
+    table_id            BIGINT NOT NULL PRIMARY KEY,
+    group_name          VARCHAR(64) NOT NULL,
+    status_code         INTEGER NOT NULL DEFAULT 0,

Review Comment:
   0 status_code makes no sense, do you mean 700(IDLE)?



-- 
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: commits-unsubscribe@amoro.apache.org

For queries about this service, please contact Infrastructure at:
users@infra.apache.org


Re: [PR] [AMORO-3747] Introducing a more general TableRuntime storage structure [amoro]

Posted by "baiyangtx (via GitHub)" <gi...@apache.org>.
baiyangtx commented on code in PR #3748:
URL: https://github.com/apache/amoro/pull/3748#discussion_r2299567789


##########
amoro-ams/src/main/resources/mysql/ams-mysql-init.sql:
##########
@@ -112,28 +112,27 @@ CREATE TABLE `table_metadata`
 CREATE TABLE `table_runtime`
 (
     `table_id`                      bigint(20) NOT NULL,
-    `catalog_name`                  varchar(64) NOT NULL COMMENT 'Catalog name',
-    `db_name`                       varchar(128) NOT NULL COMMENT 'Database name',
-    `table_name`                    varchar(256) NOT NULL COMMENT 'Table name',
-    `current_snapshot_id`           bigint(20) NOT NULL DEFAULT '-1' COMMENT 'Base table current snapshot id',
-    `current_change_snapshotId`     bigint(20) DEFAULT NULL COMMENT 'Change table current snapshot id',
-    `last_optimized_snapshotId`     bigint(20) NOT NULL DEFAULT '-1' COMMENT 'last optimized snapshot id',
-    `last_optimized_change_snapshotId`     bigint(20) NOT NULL DEFAULT '-1' COMMENT 'last optimized change snapshot id',
-    `last_major_optimizing_time`    timestamp NULL DEFAULT NULL COMMENT 'Latest Major Optimize time for all partitions',
-    `last_minor_optimizing_time`    timestamp NULL DEFAULT NULL COMMENT 'Latest Minor Optimize time for all partitions',
-    `last_full_optimizing_time`     timestamp NULL DEFAULT NULL COMMENT 'Latest Full Optimize time for all partitions',
-    `optimizing_status_code`        int DEFAULT 700 COMMENT 'Table optimize status code: 100(FULL_OPTIMIZING), 200(MAJOR_OPTIMIZING), 300(MINOR_OPTIMIZING), 400(COMMITTING), 500(PLANING), 600(PENDING), 700(IDLE)',
-    `optimizing_status_start_time`  timestamp(3) default CURRENT_TIMESTAMP(3) COMMENT 'Table optimize status start time',
-    `optimizing_process_id`         bigint(20) NOT NULL COMMENT 'optimizing_procedure UUID',
-    `optimizer_group`               varchar(64) NOT NULL,
-    `table_config`                  mediumtext,
-    `optimizing_config`             mediumtext,
-    `pending_input`                 mediumtext,
-    `table_summary`                 mediumtext,
+    `group_name`                    varchar(64) NOT NULL,
+    `status_code`                   int DEFAULT 0 NOT NULL COMMENT 'Table runtime status code.',

Review Comment:
   OK.



-- 
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: commits-unsubscribe@amoro.apache.org

For queries about this service, please contact Infrastructure at:
users@infra.apache.org


Re: [PR] [AMORO-3747] Introducing a more general TableRuntime storage structure [amoro]

Posted by "baiyangtx (via GitHub)" <gi...@apache.org>.
baiyangtx commented on code in PR #3748:
URL: https://github.com/apache/amoro/pull/3748#discussion_r2299566355


##########
amoro-ams/src/main/java/org/apache/amoro/server/dashboard/controller/TableController.java:
##########
@@ -685,11 +686,6 @@ public void cancelOptimizingProcess(Context ctx) {
     ServerTableIdentifier serverTableIdentifier =

Review Comment:
   I have add check logic.



-- 
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: commits-unsubscribe@amoro.apache.org

For queries about this service, please contact Infrastructure at:
users@infra.apache.org


Re: [PR] [AMORO-3747] Introducing a more general TableRuntime storage structure [amoro]

Posted by "baiyangtx (via GitHub)" <gi...@apache.org>.
baiyangtx commented on code in PR #3748:
URL: https://github.com/apache/amoro/pull/3748#discussion_r2299567386


##########
amoro-ams/src/main/java/org/apache/amoro/server/table/AbstractTableRuntime.java:
##########
@@ -0,0 +1,99 @@
+/*
+ * 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.
+ */
+
+package org.apache.amoro.server.table;
+
+import org.apache.amoro.Action;
+import org.apache.amoro.ServerTableIdentifier;
+import org.apache.amoro.SupportsProcessPlugins;
+import org.apache.amoro.TableFormat;
+import org.apache.amoro.TableRuntime;
+import org.apache.amoro.config.TableConfiguration;
+import org.apache.amoro.process.AmoroProcess;
+import org.apache.amoro.process.ProcessFactory;
+import org.apache.amoro.process.TableProcessState;
+import org.apache.amoro.server.persistence.PersistentBase;
+import org.apache.amoro.table.TableRuntimeStore;
+
+import java.util.List;
+
+public abstract class AbstractTableRuntime extends PersistentBase
+    implements TableRuntime, SupportsProcessPlugins {
+
+  private final TableRuntimeStore store;
+
+  protected AbstractTableRuntime(TableRuntimeStore store) {
+    this.store = store;
+  }
+
+  public TableRuntimeStore store() {
+    return store;
+  }
+
+  @Override
+  public ServerTableIdentifier getTableIdentifier() {
+    return store().getTableIdentifier();
+  }
+
+  @Override
+  public TableConfiguration getTableConfiguration() {
+    return TableConfigurations.parseTableConfig(store().getTableConfig());
+  }
+
+  @Override
+  public TableFormat getFormat() {
+    return store().getTableIdentifier().getFormat();
+  }
+
+  @Override
+  public String getGroupName() {
+    return store().getGroupName();
+  }
+
+  public int getStatusCode() {
+    return store().getStatusCode();
+  }
+
+  @Override
+  public AmoroProcess<? extends TableProcessState> trigger(Action action) {
+    return null;

Review Comment:
   I have make it abstract



-- 
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: commits-unsubscribe@amoro.apache.org

For queries about this service, please contact Infrastructure at:
users@infra.apache.org


Re: [PR] [AMORO-3747] Introducing a more general TableRuntime storage structure [amoro]

Posted by "baiyangtx (via GitHub)" <gi...@apache.org>.
baiyangtx commented on code in PR #3748:
URL: https://github.com/apache/amoro/pull/3748#discussion_r2299567013


##########
amoro-ams/src/main/java/org/apache/amoro/server/table/AbstractTableRuntime.java:
##########
@@ -0,0 +1,99 @@
+/*
+ * 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.
+ */
+
+package org.apache.amoro.server.table;
+
+import org.apache.amoro.Action;
+import org.apache.amoro.ServerTableIdentifier;
+import org.apache.amoro.SupportsProcessPlugins;
+import org.apache.amoro.TableFormat;
+import org.apache.amoro.TableRuntime;
+import org.apache.amoro.config.TableConfiguration;
+import org.apache.amoro.process.AmoroProcess;
+import org.apache.amoro.process.ProcessFactory;
+import org.apache.amoro.process.TableProcessState;
+import org.apache.amoro.server.persistence.PersistentBase;
+import org.apache.amoro.table.TableRuntimeStore;
+
+import java.util.List;
+
+public abstract class AbstractTableRuntime extends PersistentBase
+    implements TableRuntime, SupportsProcessPlugins {
+
+  private final TableRuntimeStore store;
+
+  protected AbstractTableRuntime(TableRuntimeStore store) {
+    this.store = store;
+  }
+
+  public TableRuntimeStore store() {
+    return store;
+  }
+
+  @Override
+  public ServerTableIdentifier getTableIdentifier() {
+    return store().getTableIdentifier();
+  }
+
+  @Override
+  public TableConfiguration getTableConfiguration() {
+    return TableConfigurations.parseTableConfig(store().getTableConfig());
+  }
+
+  @Override
+  public TableFormat getFormat() {

Review Comment:
   I have remove the implement.



-- 
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: commits-unsubscribe@amoro.apache.org

For queries about this service, please contact Infrastructure at:
users@infra.apache.org


Re: [PR] [AMORO-3747] Introducing a more general TableRuntime storage structure [amoro]

Posted by "zhoujinsong (via GitHub)" <gi...@apache.org>.
zhoujinsong commented on code in PR #3748:
URL: https://github.com/apache/amoro/pull/3748#discussion_r2299691783


##########
amoro-common/src/main/java/org/apache/amoro/table/StateKey.java:
##########
@@ -0,0 +1,203 @@
+/*
+ * 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.
+ */
+
+package org.apache.amoro.table;
+
+import org.apache.amoro.shade.guava32.com.google.common.base.Preconditions;
+import org.apache.amoro.shade.guava32.com.google.common.collect.Maps;
+import org.apache.amoro.shade.jackson2.com.fasterxml.jackson.core.JsonProcessingException;
+import org.apache.amoro.shade.jackson2.com.fasterxml.jackson.core.type.TypeReference;
+import org.apache.amoro.shade.jackson2.com.fasterxml.jackson.databind.DeserializationFeature;
+import org.apache.amoro.shade.jackson2.com.fasterxml.jackson.databind.ObjectMapper;
+import org.apache.commons.lang3.StringUtils;
+
+import java.util.Collections;
+import java.util.Map;
+import java.util.Objects;
+import java.util.function.BiFunction;
+import java.util.function.Function;
+
+public class StateKey<T> {

Review Comment:
   Maybe add some comments for these new classes/interfaces?



-- 
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: commits-unsubscribe@amoro.apache.org

For queries about this service, please contact Infrastructure at:
users@infra.apache.org


Re: [PR] [AMORO-3747] Introducing a more general TableRuntime storage structure [amoro]

Posted by "baiyangtx (via GitHub)" <gi...@apache.org>.
baiyangtx merged PR #3748:
URL: https://github.com/apache/amoro/pull/3748


-- 
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: commits-unsubscribe@amoro.apache.org

For queries about this service, please contact Infrastructure at:
users@infra.apache.org