Skip to content

Commit

Permalink
Fixed read-only store grandfathering script to now output metadata
Browse files Browse the repository at this point in the history
  • Loading branch information
rsumbaly committed Oct 6, 2010
1 parent 31387a8 commit 64028c5
Show file tree
Hide file tree
Showing 4 changed files with 58 additions and 23 deletions.
26 changes: 19 additions & 7 deletions bin/grandfather-readonly.sh
Expand Up @@ -15,39 +15,51 @@
# See the License for the specific language governing permissions and # See the License for the specific language governing permissions and
# limitations under the License. # limitations under the License.
# #
# One time grandfathering script to convert all read-only store dirs to
# new format
if [ $# -ne 1 ]; if [ $# -ne 1 ];
then then
echo 'USAGE: bin/grandfather-readonly.sh [readonly-folder]' echo 'USAGE: bin/grandfather-readonly.sh [readonly-folder]'
exit 1 exit 1
fi fi
# Read args # Read args
READ_ONLY_DIR=$1 READ_ONLY_DIR=$1


# Create temporary metadata file
METADATA_FILE="/tmp/$(basename $0).$$.tmp"
echo "{\"format\":\"ro0\"}" > $METADATA_FILE

for stores in $READ_ONLY_DIR/* for stores in $READ_ONLY_DIR/*
do do
if [ -d $stores ]; then if [ -d $stores ]; then


echo ---Working on store ${stores} ---
# Convert all to .temp # Convert all to .temp
numVersions=`find $stores -name version-* | grep -v .bak | grep -v .temp | wc -l` numVersions=`find $stores -name version-* | grep -v .bak | grep -v .temp | wc -l`
maxVersion=`find $stores -name version-* | grep -v .bak | grep -v .temp | awk -F'-' '{print $2}' | sort -n | tail -1`
if [ $numVersions -eq 1 ]; then
cp $METADATA_FILE ${stores}/version-${maxVersion}/.metadata
echo Added metadata to ${stores}/version-${maxVersion}
fi
if [ $numVersions -gt 1 ]; then if [ $numVersions -gt 1 ]; then
maxVersion=`find $stores -name version-* | grep -v .bak | grep -v .temp | awk -F'-' '{print $2}' | sort -n | tail -1`
for versionDirNo in `find $stores -name version-* | grep -v .bak | grep -v .temp | awk -F'-' '{print $2}' | sort -n` for versionDirNo in `find $stores -name version-* | grep -v .bak | grep -v .temp | awk -F'-' '{print $2}' | sort -n`
do do
echo $stores/version-$versionDirNo $stores/version-$maxVersion.temp mv ${stores}/version-${versionDirNo} ${stores}/version-${maxVersion}.temp
mv $stores/version-$versionDirNo $stores/version-$maxVersion.temp echo Moved ${stores}/version-${versionDirNo} to ${stores}/version-${maxVersion}.temp
cp $METADATA_FILE ${stores}/version-${maxVersion}.temp/.metadata
echo Added metadata to ${stores}/version-${maxVersion}.temp
let maxVersion=maxVersion-1 let maxVersion=maxVersion-1
done done
echo '-------'
fi fi


# Convert all .temp to normal # Convert all .temp to normal
numVersionsTmp=`find $stores -name version-*.temp | grep -v .bak | wc -l` numVersionsTmp=`find $stores -name version-*.temp | grep -v .bak | wc -l`
if [ $numVersionsTmp -gt 1 ]; then if [ $numVersionsTmp -gt 1 ]; then
for versionDir in `find $stores -name version-*.temp | grep -v .bak | awk -F'.' '{print $1}'` for versionDir in `find $stores -name version-*.temp | grep -v .bak | awk -F'.' '{print $1}'`
do do
mv $versionDir.temp $versionDir mv ${versionDir}.temp ${versionDir}
echo Moved ${versionDir}.temp to ${versionDir}
done done
echo '======='
fi fi
fi fi
done done
Expand Down
Expand Up @@ -132,6 +132,7 @@ private List<ReadOnlyStorageEngine> getReadOnlyStores(VoldemortServer server) {
@Override @Override
public void doGet(HttpServletRequest req, HttpServletResponse resp) throws ServletException, public void doGet(HttpServletRequest req, HttpServletResponse resp) throws ServletException,
IOException { IOException {
initStores((VoldemortServer) getServletContext().getAttribute(VoldemortServletContextListener.SERVER_KEY));
Map<String, Object> params = Maps.newHashMap(); Map<String, Object> params = Maps.newHashMap();
params.put("stores", stores); params.put("stores", stores);
velocityEngine.render("read-only-mgmt.vm", params, resp.getOutputStream()); velocityEngine.render("read-only-mgmt.vm", params, resp.getOutputStream());
Expand Down Expand Up @@ -162,7 +163,6 @@ private void doSwap(HttpServletRequest req, HttpServletResponse resp) throws IOE
ServletException { ServletException {
String dir = getRequired(req, "dir"); String dir = getRequired(req, "dir");
String storeName = getRequired(req, "store"); String storeName = getRequired(req, "store");
String formatString = getOptional(req, "format");


ReadOnlyStorageEngine store = this.getStore(storeName); ReadOnlyStorageEngine store = this.getStore(storeName);
if(store == null) if(store == null)
Expand Down Expand Up @@ -200,15 +200,21 @@ private void doFetch(HttpServletRequest req, HttpServletResponse resp) throws IO
File fetchDir = null; File fetchDir = null;
if(fileFetcher == null) { if(fileFetcher == null) {


logger.warn("File fetcher class has not instantiated correctly"); logger.warn("File fetcher class has not instantiated correctly. Assuming local file");
fetchDir = new File(fetchUrl);
if(!Utils.isReadableDir(fetchUrl)) {
throw new VoldemortException("Fetch url " + fetchUrl + " is not readable");
}

fetchDir = new File(store.getStoreDirPath(), "version-" + Long.toString(pushVersion));
Utils.move(new File(fetchUrl), fetchDir);


} else { } else {
logger.info("Executing fetch of " + fetchUrl); logger.info("Executing fetch of " + fetchUrl);


try { try {
fetchDir = fileFetcher.fetch(fetchUrl, store.getStoreDirPath() + File.separator fetchDir = fileFetcher.fetch(fetchUrl, store.getStoreDirPath() + File.separator
+ "version-" + pushVersion); + "version-" + Long.toString(pushVersion));


if(fetchDir == null) { if(fetchDir == null) {
throw new ServletException("File fetcher failed for " + fetchUrl throw new ServletException("File fetcher failed for " + fetchUrl
Expand Down Expand Up @@ -255,6 +261,7 @@ private String getRequired(HttpServletRequest req, String name) throws ServletEx
} }


private ReadOnlyStorageEngine getStore(String storeName) throws ServletException { private ReadOnlyStorageEngine getStore(String storeName) throws ServletException {
initStores((VoldemortServer) getServletContext().getAttribute(VoldemortServletContextListener.SERVER_KEY));
for(ReadOnlyStorageEngine store: this.stores) for(ReadOnlyStorageEngine store: this.stores)
if(store.getName().equals(storeName)) if(store.getName().equals(storeName))
return store; return store;
Expand Down
Expand Up @@ -237,8 +237,9 @@ public VAdminProto.GetROCurrentVersionDirResponse handleGetROCurrentVersionDir(V
try { try {
for(String storeName: storeNames) { for(String storeName: storeNames) {


ReadOnlyStorageEngine store = (ReadOnlyStorageEngine) getStorageEngine(storeRepository, ReadOnlyStorageEngine store = getReadOnlyStorageEngine(metadataStore,
storeName); storeRepository,
storeName);
VAdminProto.ROStoreVersionDirMap storeResponse = VAdminProto.ROStoreVersionDirMap.newBuilder() VAdminProto.ROStoreVersionDirMap storeResponse = VAdminProto.ROStoreVersionDirMap.newBuilder()
.setStoreName(storeName) .setStoreName(storeName)
.setStoreDir(store.getCurrentDirPath()) .setStoreDir(store.getCurrentDirPath())
Expand All @@ -260,8 +261,9 @@ public VAdminProto.GetROMaxVersionDirResponse handleGetROMaxVersionDir(VAdminPro
try { try {
for(String storeName: storeNames) { for(String storeName: storeNames) {


ReadOnlyStorageEngine store = (ReadOnlyStorageEngine) getStorageEngine(storeRepository, ReadOnlyStorageEngine store = getReadOnlyStorageEngine(metadataStore,
storeName); storeRepository,
storeName);
File storeDirPath = new File(store.getStoreDirPath()); File storeDirPath = new File(store.getStoreDirPath());


if(!storeDirPath.exists()) if(!storeDirPath.exists())
Expand Down Expand Up @@ -406,8 +408,9 @@ public VAdminProto.RollbackStoreResponse handleRollbackStore(VAdminProto.Rollbac
VAdminProto.RollbackStoreResponse.Builder response = VAdminProto.RollbackStoreResponse.newBuilder(); VAdminProto.RollbackStoreResponse.Builder response = VAdminProto.RollbackStoreResponse.newBuilder();


try { try {
ReadOnlyStorageEngine store = (ReadOnlyStorageEngine) getStorageEngine(storeRepository, ReadOnlyStorageEngine store = getReadOnlyStorageEngine(metadataStore,
storeName); storeRepository,
storeName);


File rollbackVersionDir = new File(store.getStoreDirPath(), "version-" + pushVersion); File rollbackVersionDir = new File(store.getStoreDirPath(), "version-" + pushVersion);


Expand Down Expand Up @@ -446,8 +449,10 @@ public VAdminProto.SwapStoresAndCleanStateResponse handleSwapStoresAndCleanState
} }


private void swapStore(String storeName, String directory) throws VoldemortException { private void swapStore(String storeName, String directory) throws VoldemortException {
ReadOnlyStorageEngine store = (ReadOnlyStorageEngine) getStorageEngine(storeRepository,
storeName); ReadOnlyStorageEngine store = getReadOnlyStorageEngine(metadataStore,
storeRepository,
storeName);


if(!Utils.isReadableDir(directory)) if(!Utils.isReadableDir(directory))
throw new VoldemortException("Store directory '" + directory throw new VoldemortException("Store directory '" + directory
Expand Down Expand Up @@ -488,8 +493,9 @@ public VAdminProto.AsyncOperationStatusResponse handleFetchStore(VAdminProto.Fet
.setDescription("Fetch store") .setDescription("Fetch store")
.setStatus("started"); .setStatus("started");
try { try {
final ReadOnlyStorageEngine store = (ReadOnlyStorageEngine) getStorageEngine(storeRepository, final ReadOnlyStorageEngine store = getReadOnlyStorageEngine(metadataStore,
storeName); storeRepository,
storeName);
final long pushVersion; final long pushVersion;
if(request.hasPushVersion()) { if(request.hasPushVersion()) {
pushVersion = request.getPushVersion(); pushVersion = request.getPushVersion();
Expand Down Expand Up @@ -979,6 +985,15 @@ static int valueSize(Versioned<byte[]> value) {
return value.getValue().length + ((VectorClock) value.getVersion()).sizeInBytes() + 1; return value.getValue().length + ((VectorClock) value.getVersion()).sizeInBytes() + 1;
} }


static ReadOnlyStorageEngine getReadOnlyStorageEngine(MetadataStore metadata,
StoreRepository repo,
String name) {
if(metadata.getStoreDef(name).getType().compareTo(ReadOnlyStorageConfiguration.TYPE_NAME) != 0)
throw new VoldemortException("Store " + name
+ " is not a read-only store, cannot complete operation");
return (ReadOnlyStorageEngine) getStorageEngine(repo, name);
}

static StorageEngine<ByteArray, byte[], byte[]> getStorageEngine(StoreRepository storeRepository, static StorageEngine<ByteArray, byte[], byte[]> getStorageEngine(StoreRepository storeRepository,
String storeName) { String storeName) {
StorageEngine<ByteArray, byte[], byte[]> storageEngine = storeRepository.getStorageEngine(storeName); StorageEngine<ByteArray, byte[], byte[]> storageEngine = storeRepository.getStorageEngine(storeName);
Expand Down
Expand Up @@ -49,8 +49,9 @@ protected FetchPartitionFileStreamRequestHandler(VAdminProto.FetchPartitionFiles
throw new VoldemortException("Should be fetching partition files only for read-only stores"); throw new VoldemortException("Should be fetching partition files only for read-only stores");
} }


this.storageEngine = (ReadOnlyStorageEngine) AdminServiceRequestHandler.getStorageEngine(storeRepository, this.storageEngine = AdminServiceRequestHandler.getReadOnlyStorageEngine(metadataStore,
request.getStore()); storeRepository,
request.getStore());


this.blockSize = voldemortConfig.getAllProps() this.blockSize = voldemortConfig.getAllProps()
.getLong("partition.buffer.size.bytes", .getLong("partition.buffer.size.bytes",
Expand Down

0 comments on commit 64028c5

Please sign in to comment.