-
Notifications
You must be signed in to change notification settings - Fork 703
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
[CARBONDATA-3582] support table status file backup
When overwriting table status file, if process crashed, table status file will be in corrupted state. This can happen in an unstable environment, like in the cloud. To prevent the table corruption, user can enable a newly added CarbonProperty to enable backup of the table status before overwriting it. New CarbonProperty: ENABLE_TABLE_STATUS_BACKUP (default is false) When enabling this property, "tablestatus.backup" file will be created in the same folder of "tablestatus" file This closes #3459
- Loading branch information
1 parent
3098fec
commit 5d287b8
Showing
6 changed files
with
190 additions
and
43 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
76 changes: 76 additions & 0 deletions
76
integration/spark2/src/test/scala/org/apache/spark/carbondata/TableStatusBackupTest.scala
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,76 @@ | ||
/* | ||
* 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.spark.carbondata | ||
|
||
import java.io.IOException | ||
|
||
import mockit.{Mock, MockUp} | ||
import org.apache.spark.sql.CarbonEnv | ||
import org.apache.spark.sql.test.util.QueryTest | ||
import org.scalatest.BeforeAndAfterAll | ||
|
||
import org.apache.carbondata.core.constants.CarbonCommonConstants | ||
import org.apache.carbondata.core.datastore.impl.FileFactory | ||
import org.apache.carbondata.core.statusmanager.SegmentStatusManager | ||
import org.apache.carbondata.core.util.CarbonProperties | ||
import org.apache.carbondata.core.util.path.CarbonTablePath | ||
|
||
class TableStatusBackupTest extends QueryTest with BeforeAndAfterAll { | ||
override protected def beforeAll(): Unit = { | ||
CarbonProperties.getInstance().addProperty( | ||
CarbonCommonConstants.ENABLE_TABLE_STATUS_BACKUP, "true") | ||
sql("drop table if exists source") | ||
sql("create table source(a string) stored as carbondata") | ||
} | ||
|
||
override protected def afterAll(): Unit = { | ||
sql("drop table if exists source") | ||
CarbonProperties.getInstance().addProperty( | ||
CarbonCommonConstants.ENABLE_TABLE_STATUS_BACKUP, "false") | ||
} | ||
|
||
test("backup table status file") { | ||
sql("insert into source values ('A'), ('B')") | ||
val tablePath = CarbonEnv.getCarbonTable(None, "source")(sqlContext.sparkSession).getTablePath | ||
val tableStatusFilePath = CarbonTablePath.getTableStatusFilePath(tablePath) | ||
val oldTableStatus = SegmentStatusManager.readTableStatusFile(tableStatusFilePath) | ||
|
||
var mock = new MockUp[SegmentStatusManager]() { | ||
@Mock | ||
@throws[IOException] | ||
def mockForTest(): Unit = { | ||
throw new IOException("thrown in mock") | ||
} | ||
} | ||
|
||
val exception = intercept[IOException] { | ||
sql("insert into source values ('A'), ('B')") | ||
} | ||
assert(exception.getMessage.contains("thrown in mock")) | ||
val backupPath = tableStatusFilePath + ".backup" | ||
assert(FileFactory.isFileExist(backupPath)) | ||
val backupTableStatus = SegmentStatusManager.readTableStatusFile(backupPath) | ||
assertResult(oldTableStatus)(backupTableStatus) | ||
|
||
mock = new MockUp[SegmentStatusManager]() { | ||
@Mock | ||
def mockForTest(): Unit = { | ||
} | ||
} | ||
} | ||
} |