ajantha-bhat commented on a change in pull request #3688: [CARBONDATA-3765]
Refactor Index Metadata for CG and FG Indexes
URL: https://github.com/apache/carbondata/pull/3688#discussion_r405999660
##########
File path:
integration/spark/src/main/scala/org/apache/spark/sql/execution/command/index/CarbonRefreshIndexCommand.scala
##########
@@ -71,30 +80,81 @@ case class CarbonRefreshIndexCommand(
private def refreshIndex(
sparkSession: SparkSession,
parentTable: CarbonTable,
- indexOp: Optional[DataMapSchema]): Unit = {
- val schema = indexOp.get
+ indexMetaData: IndexMetadata): Unit = {
+ var indexInfo: util.Map[String, String] = new util.HashMap[String,
String]()
+ val allIndexesIterator = indexMetaData.getIndexesMap.entrySet().iterator()
+ breakable {
+ while (allIndexesIterator.hasNext) {
+ val currentIndex = allIndexesIterator.next()
+ if
(!currentIndex.getKey.equalsIgnoreCase(CarbonIndexProvider.SI.getIndexProviderName))
{
+ val indexIterator = currentIndex.getValue.entrySet().iterator()
+ while (indexIterator.hasNext) {
+ val indexEntry = indexIterator.next()
+ if (indexEntry.getKey.equalsIgnoreCase(indexName)) {
+ indexInfo = indexEntry.getValue
+ break()
+ }
+ }
+ }
+ }
+ }
+ if (indexInfo.isEmpty) {
+ throw new MalformedIndexCommandException(
+ "Index with name `" + indexName + "` is not present" +
+ "on table `" + parentTable.getTableName + "`")
+ }
+ val indexProviderName = indexInfo.get(CarbonCommonConstants.INDEX_PROVIDER)
+ val schema = new DataMapSchema(indexName, indexProviderName)
+ schema.setProperties(indexInfo)
if (!schema.isLazy) {
throw new MalformedIndexCommandException(
s"Non-lazy index $indexName does not support manual refresh")
}
val provider = DataMapManager.get().getDataMapProvider(parentTable,
schema, sparkSession)
provider.rebuild()
+ // enable bloom or lucene index
+ // get metadata lock to avoid concurrent create index operations
+ val metadataLock = CarbonLockFactory.getCarbonLockObj(
+ parentTable.getAbsoluteTableIdentifier,
+ LockUsage.METADATA_LOCK)
+ try {
+ if (metadataLock.lockWithRetries()) {
+ LOGGER.info(s"Acquired the metadata lock for table " +
+ s"${ parentTable.getDatabaseName}.${
parentTable.getTableName }")
+ val oldIndexInfo = parentTable.getIndexInfo
+ val updatedIndexInfo = IndexTableInfo.enableIndex(oldIndexInfo,
indexName)
+
+ // set index information in parent table
+ val parentIndexMetadata =
+
IndexMetadata.deserialize(parentTable.getTableInfo.getFactTable.getTableProperties
Review comment:
we already deserialize and store it in parent carbon table indexMeta right ?
why not directly use 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.
For queries about this service, please contact Infrastructure at:
[email protected]
With regards,
Apache Git Services