Skip to content

Commit

Permalink
[CARBONDATA-2538] added filter while listing files from writer path
Browse files Browse the repository at this point in the history
1. Added filter to list only index and carbondata files. So even if the lock files are present proper exception can be thrown
2. Updated complex type docs

This closes #2344
  • Loading branch information
kunal642 authored and manishgupta88 committed May 29, 2018
1 parent 8b80b12 commit d777318
Show file tree
Hide file tree
Showing 5 changed files with 20 additions and 6 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -892,7 +892,7 @@ public boolean isFileLevelFormat() {


public long size() throws IOException {
Map<String, Long> dataIndexSize = CarbonUtil.calculateDataIndexSize(this);
Map<String, Long> dataIndexSize = CarbonUtil.calculateDataIndexSize(this, true);
Long dataSize = dataIndexSize.get(CarbonCommonConstants.CARBON_TOTAL_DATA_SIZE);
if (dataSize == null) {
dataSize = 0L;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -26,6 +26,7 @@
import org.apache.carbondata.common.annotations.InterfaceStability;
import org.apache.carbondata.core.datamap.Segment;
import org.apache.carbondata.core.datastore.filesystem.CarbonFile;
import org.apache.carbondata.core.datastore.filesystem.CarbonFileFilter;
import org.apache.carbondata.core.datastore.impl.FileFactory;
import org.apache.carbondata.core.indexstore.blockletindex.SegmentIndexFileStore;
import org.apache.carbondata.core.mutate.UpdateVO;
Expand Down Expand Up @@ -138,7 +139,13 @@ private String getSegmentID(String carbonIndexFileName, String indexFilePath) {
@Override public void takeCarbonIndexFileSnapShot() throws IOException {
// Read the current file Path get the list of indexes from the path.
CarbonFile file = FileFactory.getCarbonFile(carbonFilePath);
if (file.listFiles().length == 0) {
CarbonFile[] files = file.listFiles(new CarbonFileFilter() {
@Override public boolean accept(CarbonFile file) {
return file.getName().endsWith(CarbonTablePath.INDEX_FILE_EXT) || file.getName()
.endsWith(CarbonTablePath.CARBON_DATA_EXT);
}
});
if (files.length == 0) {
// For nonTransactional table, files can be removed at any point of time.
// So cannot assume files will be present
throw new IOException("No files are present in the table location :" + carbonFilePath);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -2550,7 +2550,8 @@ public static int isFilterPresent(byte[][] filterValues,
/**
* This method will calculate the data size and index size for carbon table
*/
public static Map<String, Long> calculateDataIndexSize(CarbonTable carbonTable)
public static Map<String, Long> calculateDataIndexSize(CarbonTable carbonTable,
Boolean updateSize)
throws IOException {
Map<String, Long> dataIndexSizeMap = new HashMap<String, Long>();
long dataSize = 0L;
Expand All @@ -2565,7 +2566,11 @@ public static Map<String, Long> calculateDataIndexSize(CarbonTable carbonTable)
SegmentStatusManager segmentStatusManager = new SegmentStatusManager(identifier);
ICarbonLock carbonLock = segmentStatusManager.getTableStatusLock();
try {
if (carbonLock.lockWithRetries()) {
boolean lockAcquired = true;
if (updateSize) {
lockAcquired = carbonLock.lockWithRetries();
}
if (lockAcquired) {
LOGGER.info("Acquired lock for table for table status updation");
String metadataPath = carbonTable.getMetadataPath();
LoadMetadataDetails[] loadMetadataDetails =
Expand Down Expand Up @@ -2593,7 +2598,7 @@ public static Map<String, Long> calculateDataIndexSize(CarbonTable carbonTable)
}
}
// If it contains old segment, write new load details
if (needUpdate) {
if (needUpdate && updateSize) {
SegmentStatusManager.writeLoadDetailsIntoFile(
CarbonTablePath.getTableStatusFilePath(identifier.getTablePath()),
loadMetadataDetails);
Expand Down
2 changes: 2 additions & 0 deletions docs/supported-data-types-in-carbondata.md
Original file line number Diff line number Diff line change
Expand Up @@ -38,6 +38,8 @@
* Complex Types
* arrays: ARRAY``<data_type>``
* structs: STRUCT``<col_name : data_type COMMENT col_comment, ...>``

**NOTE**: Only 2 level complex type schema is supported for now.

* Other Types
* BOOLEAN
Original file line number Diff line number Diff line change
Expand Up @@ -96,7 +96,7 @@ private[sql] case class CarbonDescribeFormattedCommand(
val tableComment = tblProps.asScala.getOrElse(CarbonCommonConstants.TABLE_COMMENT, "")
results ++= Seq(("Comment", tableComment, ""))
results ++= Seq(("Table Block Size ", carbonTable.getBlockSizeInMB + " MB", ""))
val dataIndexSize = CarbonUtil.calculateDataIndexSize(carbonTable)
val dataIndexSize = CarbonUtil.calculateDataIndexSize(carbonTable, false)
if (!dataIndexSize.isEmpty) {
results ++= Seq((CarbonCommonConstants.TABLE_DATA_SIZE,
dataIndexSize.get(CarbonCommonConstants.CARBON_TOTAL_DATA_SIZE).toString, ""))
Expand Down

0 comments on commit d777318

Please sign in to comment.