-
Notifications
You must be signed in to change notification settings - Fork 2.9k
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #1344 from uronce-cc/wip_master_client_rawtable
[TACHYON-820] Meta for the new RawTableMaster
- Loading branch information
Showing
4 changed files
with
234 additions
and
2 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
79 changes: 79 additions & 0 deletions
79
servers/src/main/java/tachyon/master/next/rawtable/meta/RawTable.java
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,79 @@ | ||
/* | ||
* Licensed to the University of California, Berkeley 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 tachyon.master.next.rawtable.meta; | ||
|
||
import java.nio.ByteBuffer; | ||
|
||
import tachyon.util.io.BufferUtils; | ||
|
||
public class RawTable { | ||
/** Table ID */ | ||
private final int mId; | ||
/** Number of columns */ | ||
private final int mColumns; | ||
/** Table metadata */ | ||
private ByteBuffer mMetadata; | ||
|
||
/** | ||
* Create a new RawTable with metadata set to null. metadata can later be set via | ||
* {@link #setMetadata(java.nio.ByteBuffer)}. | ||
* | ||
* @param id table id | ||
* @param columns number of columns | ||
*/ | ||
public RawTable(int id, int columns) { | ||
mId = id; | ||
mColumns = columns; | ||
mMetadata = null; | ||
} | ||
|
||
/** | ||
* Create a new RawTable with metadata set to a ByteBuffer. | ||
* | ||
* @param id table id | ||
* @param columns number of columns | ||
* @param metadata table metadata, if is null, the internal metadata is set to an empty buffer, | ||
* otherwise, the provided buffer will be copied into the internal buffer. | ||
* @return the created RawTable | ||
*/ | ||
public RawTable(int id, int columns, ByteBuffer metadata) { | ||
mId = id; | ||
mColumns = columns; | ||
setMetadata(metadata); | ||
} | ||
|
||
public int getId() { | ||
return mId; | ||
} | ||
|
||
public int getColumns() { | ||
return mColumns; | ||
} | ||
|
||
public ByteBuffer getMetadata() { | ||
return mMetadata; | ||
} | ||
|
||
/** | ||
* Set the table metadata. If the specified metadata is null, the internal metadata will be set to | ||
* an empty byte buffer, otherwise, the provided metadata will be copied into the internal buffer. | ||
* | ||
* @param metadata the metadata to be set | ||
*/ | ||
public void setMetadata(ByteBuffer metadata) { | ||
mMetadata = BufferUtils.cloneByteBuffer(metadata); | ||
} | ||
} |
126 changes: 126 additions & 0 deletions
126
servers/src/main/java/tachyon/master/next/rawtable/meta/RawTables.java
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,126 @@ | ||
/* | ||
* Licensed to the University of California, Berkeley 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 tachyon.master.next.rawtable.meta; | ||
|
||
import java.nio.ByteBuffer; | ||
|
||
import tachyon.master.next.IndexedSet; | ||
import tachyon.thrift.TableDoesNotExistException; | ||
import tachyon.thrift.TachyonException; | ||
import tachyon.util.io.BufferUtils; | ||
|
||
/** | ||
* All RawTables managed by RawTableMaster. | ||
*/ | ||
public class RawTables { | ||
private final IndexedSet.FieldIndex<RawTable> mIdIndex = new IndexedSet.FieldIndex<RawTable>() { | ||
@Override | ||
public Object getFieldValue(RawTable o) { | ||
return o.getId(); | ||
} | ||
}; | ||
/** A set of TableInfo indexed by table id */ | ||
private final IndexedSet<RawTable> mTables = new IndexedSet<RawTable>(mIdIndex); | ||
|
||
/** | ||
* Add a raw table. | ||
* | ||
* @param tableId The id of the raw table | ||
* @param columns The number of columns in the raw table | ||
* @param metadata The additional metadata of the raw table | ||
* @return true if the raw table does not exist before and successfully added, false otherwise | ||
* @throws TachyonException when metadata size is larger than maximum configured size | ||
*/ | ||
public synchronized boolean add(int tableId, int columns, ByteBuffer metadata) | ||
throws TachyonException { | ||
if (mTables.contains(mIdIndex, tableId)) { | ||
return false; | ||
} | ||
mTables.add(new RawTable(tableId, columns, metadata)); | ||
return true; | ||
} | ||
|
||
/** | ||
* Remove a raw table. | ||
* | ||
* @param tableId The id of the raw table | ||
* @return true if the table exists and successfully removed, false otherwise | ||
*/ | ||
public synchronized boolean remove(int tableId) { | ||
return mTables.removeByField(mIdIndex, tableId); | ||
} | ||
|
||
/** | ||
* Whether the raw table exists. | ||
* | ||
* @param tableId the id of the raw table | ||
* @return true if the table exists, false otherwise. | ||
*/ | ||
public synchronized boolean contains(int tableId) { | ||
return mTables.contains(mIdIndex, tableId); | ||
} | ||
|
||
/** | ||
* Get the number of the columns of a raw table. | ||
* | ||
* @param tableId the id of the raw table | ||
* @return the number of the columns, -1 if the table does not exist. | ||
*/ | ||
public synchronized int getColumns(int tableId) { | ||
RawTable table = mTables.getFirstByField(mIdIndex, tableId); | ||
return null == table ? -1 : table.getColumns(); | ||
} | ||
|
||
/** | ||
* Get the metadata of the specified raw table. | ||
* | ||
* @param tableId The id of the raw table | ||
* @return null if it has no metadata, or a copy of the internal metadata | ||
*/ | ||
public synchronized ByteBuffer getMetadata(int tableId) { | ||
RawTable table = mTables.getFirstByField(mIdIndex, tableId); | ||
return null == table ? null : BufferUtils.cloneByteBuffer(table.getMetadata()); | ||
} | ||
|
||
/** | ||
* Get the raw table info. | ||
* | ||
* @param tableId the raw table id. | ||
* @return the raw table info if the table exists, null otherwise. | ||
*/ | ||
public synchronized RawTable getTableInfo(int tableId) { | ||
return mTables.getFirstByField(mIdIndex, tableId); | ||
} | ||
|
||
/** | ||
* Update the metadata of the specified raw table. If the new specified metadata is null, the | ||
* internal metadata will be updated to an empty byte buffer. | ||
* | ||
* @param tableId The id of the raw table | ||
* @param metadata The new metadata of the raw table | ||
* @throws TableDoesNotExistException when the table does not exist | ||
*/ | ||
public synchronized void updateMetadata(int tableId, ByteBuffer metadata) | ||
throws TableDoesNotExistException { | ||
RawTable table = mTables.getFirstByField(mIdIndex, tableId); | ||
|
||
if (null == table) { | ||
throw new TableDoesNotExistException("The raw table " + tableId + " does not exist."); | ||
} | ||
|
||
table.setMetadata(metadata); | ||
} | ||
} |