Skip to content

Commit 3ab8481

Browse files
committed
Refactor LoadTableMetaDataFailedException
1 parent 6117a3d commit 3ab8481

File tree

5 files changed

+15
-10
lines changed

5 files changed

+15
-10
lines changed

docs/document/content/user-manual/error-code/sql-error-code.cn.md

+1
Original file line numberDiff line numberDiff line change
@@ -21,6 +21,7 @@ SQL 错误码以标准的 SQL State,Vendor Code 和详细错误信息提供,
2121
| 10004 | 42S02 | Index '%s' does not exist. |
2222
| 10005 | 42S01 | Index '%s' already exists. |
2323
| 10010 | HY000 | Rule and storage meta data mismatched, reason is: %s. |
24+
| 10012 | HY000 | Load table meta data failed for database '%s' and tables '%s'. |
2425
| 10100 | HY000 | Can not %s storage units '%s'. |
2526
| 10101 | 42S02 | There is no storage unit in database '%s'. |
2627
| 10102 | 44000 | Storage units '%s' do not exist in database '%s'. |

docs/document/content/user-manual/error-code/sql-error-code.en.md

+1
Original file line numberDiff line numberDiff line change
@@ -22,6 +22,7 @@ SQL error codes provide by standard `SQL State`, `Vendor Code` and `Reason`, whi
2222
| 10005 | 42S01 | Index '%s' already exists. |
2323
| 10010 | HY000 | Rule and storage meta data mismatched, reason is: %s. |
2424
| 10100 | HY000 | Can not %s storage units '%s'. |
25+
| 10012 | HY000 | Load table meta data failed for database '%s' and tables '%s'. |
2526
| 10101 | 42S02 | There is no storage unit in database '%s'. |
2627
| 10102 | 44000 | Storage units '%s' do not exist in database '%s'. |
2728
| 10103 | 44000 | Storage unit '%s' still used by '%s'. |

mode/core/src/main/java/org/apache/shardingsphere/mode/exception/LoadTableMetaDataFailedException.java

+9-2
Original file line numberDiff line numberDiff line change
@@ -20,12 +20,19 @@
2020
import org.apache.shardingsphere.infra.exception.core.external.sql.sqlstate.XOpenSQLState;
2121
import org.apache.shardingsphere.infra.exception.core.external.sql.type.kernel.category.MetaDataSQLException;
2222

23+
import java.sql.SQLException;
24+
import java.util.Collection;
25+
2326
/**
2427
* Load table meta data failed exception.
2528
*/
2629
public final class LoadTableMetaDataFailedException extends MetaDataSQLException {
2730

28-
public LoadTableMetaDataFailedException() {
29-
super(XOpenSQLState.GENERAL_ERROR, 12, "Failed to load table meta data.");
31+
public LoadTableMetaDataFailedException(final String databaseName, final SQLException cause) {
32+
super(XOpenSQLState.GENERAL_ERROR, 12, cause, "Load table meta data failed for database '%s'.", databaseName);
33+
}
34+
35+
public LoadTableMetaDataFailedException(final String databaseName, final Collection<String> needReloadTables, final SQLException cause) {
36+
super(XOpenSQLState.GENERAL_ERROR, 12, cause, "Load table meta data failed for database '%s' and tables '%s'.", databaseName, String.join(", ", needReloadTables));
3037
}
3138
}

mode/type/cluster/core/src/main/java/org/apache/shardingsphere/mode/manager/cluster/persist/service/ClusterMetaDataManagerPersistService.java

+2-6
Original file line numberDiff line numberDiff line change
@@ -18,7 +18,6 @@
1818
package org.apache.shardingsphere.mode.manager.cluster.persist.service;
1919

2020
import lombok.SneakyThrows;
21-
import lombok.extern.slf4j.Slf4j;
2221
import org.apache.shardingsphere.infra.config.rule.RuleConfiguration;
2322
import org.apache.shardingsphere.infra.database.core.type.DatabaseTypeRegistry;
2423
import org.apache.shardingsphere.infra.datasource.pool.props.domain.DataSourcePoolProperties;
@@ -58,7 +57,6 @@
5857
/**
5958
* Cluster meta data manager persist service.
6059
*/
61-
@Slf4j
6260
public final class ClusterMetaDataManagerPersistService implements MetaDataManagerPersistService {
6361

6462
private final MetaDataContextManager metaDataContextManager;
@@ -192,8 +190,7 @@ private void afterStorageUnitsDropped(final String databaseName, final MetaDataC
192190
tables.forEach(each -> metaDataPersistFacade.getDatabaseMetaDataFacade().getTable().drop(databaseName, entry.getKey(), each.getName()));
193191
}
194192
} catch (final SQLException ex) {
195-
log.error("Reload table meta failed, databaseName:{}", databaseName, ex);
196-
throw new LoadTableMetaDataFailedException();
193+
throw new LoadTableMetaDataFailedException(databaseName, ex);
197194
}
198195
Optional.ofNullable(reloadMetaDataContexts.getStatistics().getDatabaseStatistics(databaseName))
199196
.ifPresent(optional -> optional.getSchemaStatisticsMap().forEach((schemaName, schemaStatistics) -> metaDataPersistFacade.getStatisticsService()
@@ -241,8 +238,7 @@ private void reloadAlteredTables(final String databaseName, final MetaDataContex
241238
metaDataPersistFacade.getDatabaseMetaDataFacade().getTable().persist(databaseName, entry.getKey(), tables);
242239
}
243240
} catch (final SQLException ex) {
244-
log.error("Reload table meta failed, databaseName:{}, needReloadTables:{}", databaseName, needReloadTables, ex);
245-
throw new LoadTableMetaDataFailedException();
241+
throw new LoadTableMetaDataFailedException(databaseName, needReloadTables, ex);
246242
}
247243
}
248244

mode/type/standalone/core/src/main/java/org/apache/shardingsphere/mode/manager/standalone/persist/service/StandaloneMetaDataManagerPersistService.java

+2-2
Original file line numberDiff line numberDiff line change
@@ -213,7 +213,7 @@ private void afterStorageUnitsUnregistered(final String databaseName, final Stri
213213
tables.forEach(each -> metaDataPersistFacade.getDatabaseMetaDataFacade().getTable().drop(databaseName, entry.getKey(), each.getName()));
214214
}
215215
} catch (final SQLException ex) {
216-
throw new LoadTableMetaDataFailedException();
216+
throw new LoadTableMetaDataFailedException(databaseName, ex);
217217
}
218218
}
219219

@@ -278,7 +278,7 @@ private void reloadAlteredTables(final String databaseName, final Collection<Str
278278
tables.forEach(each -> metaDataContextManager.getDatabaseMetaDataManager().alterTable(databaseName, entry.getKey(), each));
279279
}
280280
} catch (final SQLException ex) {
281-
throw new LoadTableMetaDataFailedException();
281+
throw new LoadTableMetaDataFailedException(databaseName, needReloadTables, ex);
282282
}
283283
}
284284

0 commit comments

Comments
 (0)