started implementing local resource repository which stores an indexProvider which is required for local crash recovery.
git-svn-id: https://hyracks.googlecode.com/svn/branches/hyracks_lsm_tree@1916 123451ca-8445-de46-9d55-352943316053
diff --git a/hyracks-storage-common/src/main/java/edu/uci/ics/hyracks/storage/common/file/ILocalResource.java b/hyracks-storage-common/src/main/java/edu/uci/ics/hyracks/storage/common/file/ILocalResource.java
new file mode 100644
index 0000000..d387a4a
--- /dev/null
+++ b/hyracks-storage-common/src/main/java/edu/uci/ics/hyracks/storage/common/file/ILocalResource.java
@@ -0,0 +1,29 @@
+/*
+ * Copyright 2009-2012 by The Regents of the University of California
+ * Licensed 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 from
+ *
+ * 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 edu.uci.ics.hyracks.storage.common.file;
+
+import java.io.Serializable;
+
+public interface ILocalResource extends Serializable {
+ public byte[] toBytes();
+
+ public long getResourceId();
+
+ public String getResourceName();
+
+ public Object getResourceObject();
+
+ public ILocalResourceClass getResourceClass();
+}
diff --git a/hyracks-storage-common/src/main/java/edu/uci/ics/hyracks/storage/common/file/ILocalResourceClass.java b/hyracks-storage-common/src/main/java/edu/uci/ics/hyracks/storage/common/file/ILocalResourceClass.java
new file mode 100644
index 0000000..ea7fcbd
--- /dev/null
+++ b/hyracks-storage-common/src/main/java/edu/uci/ics/hyracks/storage/common/file/ILocalResourceClass.java
@@ -0,0 +1,29 @@
+/*
+ * Copyright 2009-2012 by The Regents of the University of California
+ * Licensed 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 from
+ *
+ * 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 edu.uci.ics.hyracks.storage.common.file;
+
+public interface ILocalResourceClass {
+
+ public static final int LSMBTree = 0;
+ public static final int LSMRTree = 1;
+ public static final int LSMInvertedIndex = 2;
+
+ public ILocalResource deserialize(byte[] bytes);
+
+ public byte[] serialize(ILocalResource localResource);
+
+ public int getResourceClassId();
+
+}
diff --git a/hyracks-storage-common/src/main/java/edu/uci/ics/hyracks/storage/common/file/ILocalResourceRepository.java b/hyracks-storage-common/src/main/java/edu/uci/ics/hyracks/storage/common/file/ILocalResourceRepository.java
new file mode 100644
index 0000000..147fe07
--- /dev/null
+++ b/hyracks-storage-common/src/main/java/edu/uci/ics/hyracks/storage/common/file/ILocalResourceRepository.java
@@ -0,0 +1,35 @@
+/*
+ * Copyright 2009-2012 by The Regents of the University of California
+ * Licensed 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 from
+ *
+ * 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 edu.uci.ics.hyracks.storage.common.file;
+
+import java.util.List;
+
+import edu.uci.ics.hyracks.api.exceptions.HyracksDataException;
+
+public interface ILocalResourceRepository {
+
+ public ILocalResource getResourceById(long id) throws HyracksDataException;
+
+ public ILocalResource getResourceByName(String name) throws HyracksDataException;
+
+ public void insert(ILocalResource resource) throws HyracksDataException;
+
+ public void deleteResourceById(long id) throws HyracksDataException;
+
+ public void deleteResourceByName(String name) throws HyracksDataException;
+
+ public List<ILocalResource> getAllResources() throws HyracksDataException;
+
+}
diff --git a/hyracks-storage-common/src/main/java/edu/uci/ics/hyracks/storage/common/file/ILocalResourceRepositoryFactory.java b/hyracks-storage-common/src/main/java/edu/uci/ics/hyracks/storage/common/file/ILocalResourceRepositoryFactory.java
new file mode 100644
index 0000000..6fd4b2c
--- /dev/null
+++ b/hyracks-storage-common/src/main/java/edu/uci/ics/hyracks/storage/common/file/ILocalResourceRepositoryFactory.java
@@ -0,0 +1,21 @@
+/*
+ * Copyright 2009-2012 by The Regents of the University of California
+ * Licensed 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 from
+ *
+ * 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 edu.uci.ics.hyracks.storage.common.file;
+
+import java.util.List;
+
+public interface ILocalResourceRepositoryFactory {
+ public ILocalResourceRepository createRepository();
+}
diff --git a/hyracks-storage-common/src/main/java/edu/uci/ics/hyracks/storage/common/file/IndexLocalResourceRepository.java b/hyracks-storage-common/src/main/java/edu/uci/ics/hyracks/storage/common/file/IndexLocalResourceRepository.java
new file mode 100644
index 0000000..f4ead26
--- /dev/null
+++ b/hyracks-storage-common/src/main/java/edu/uci/ics/hyracks/storage/common/file/IndexLocalResourceRepository.java
@@ -0,0 +1,135 @@
+package edu.uci.ics.hyracks.storage.common.file;
+
+import java.io.File;
+import java.io.FileOutputStream;
+import java.io.IOException;
+import java.io.ObjectOutputStream;
+import java.util.HashMap;
+import java.util.List;
+import java.util.Map;
+
+import edu.uci.ics.hyracks.api.exceptions.HyracksDataException;
+import edu.uci.ics.hyracks.api.io.IIOManager;
+
+public class IndexLocalResourceRepository implements ILocalResourceRepository {
+
+ private final IIOManager ioManager;
+ private final List<String> mountPoints;
+ private final String rootDir;
+ private static final String METADATA_FILE_NAME = ".metadata";
+ private Map<String, ILocalResource> name2ResourceMap = new HashMap<String, ILocalResource>();
+ private Map<Long, ILocalResource> id2ResourceMap = new HashMap<Long, ILocalResource>();
+
+ public IndexLocalResourceRepository(IIOManager ioManager, List<String> mountPoints, String rootDir)
+ throws HyracksDataException {
+ this.ioManager = ioManager;
+ this.mountPoints = mountPoints;
+ this.rootDir = rootDir;
+
+ //TODO initialize the Maps
+ }
+
+ @Override
+ public ILocalResource getResourceById(long id) throws HyracksDataException {
+ return id2ResourceMap.get(id);
+ }
+
+ @Override
+ public ILocalResource getResourceByName(String name) throws HyracksDataException {
+ return id2ResourceMap.get(name);
+ }
+
+ @Override
+ public synchronized void insert(ILocalResource resource) throws HyracksDataException {
+ long id = resource.getResourceId();
+
+ if (id2ResourceMap.containsKey(id)) {
+ throw new HyracksDataException("Duplicate resource");
+ }
+ ILocalResource resourceClone = cloneResource(resource);
+ id2ResourceMap.put(id, resourceClone);
+ name2ResourceMap.put(resource.getResourceName(), resourceClone);
+
+ FileOutputStream fos = null;
+ ObjectOutputStream oosToFos = null;
+ try {
+ fos = new FileOutputStream(getFileName(mountPoints.get(0), resource.getResourceName()));
+ oosToFos = new ObjectOutputStream(fos);
+ byte[] outputBytes = resource.getResourceClass().serialize(resource);
+ oosToFos.writeInt(outputBytes.length);
+ oosToFos.write(outputBytes);
+ oosToFos.flush();
+ } catch (IOException e) {
+ throw new HyracksDataException(e);
+ } finally {
+ if (oosToFos != null) {
+ try {
+ oosToFos.close();
+ } catch (IOException e) {
+ throw new HyracksDataException(e);
+ }
+ }
+ if (oosToFos == null && fos != null) {
+ try {
+ fos.close();
+ } catch (IOException e) {
+ throw new HyracksDataException(e);
+ }
+ }
+ }
+ }
+
+ @Override
+ public synchronized void deleteResourceById(long id) throws HyracksDataException {
+ ILocalResource resource = id2ResourceMap.get(id);
+ if (resource == null) {
+ throw new HyracksDataException("Resource doesn't exist");
+ }
+ id2ResourceMap.remove(id);
+ name2ResourceMap.remove(resource.getResourceName());
+ File file = new File(getFileName(mountPoints.get(0), resource.getResourceName()));
+ file.delete();
+ }
+
+ @Override
+ public synchronized void deleteResourceByName(String name) throws HyracksDataException {
+ ILocalResource resource = id2ResourceMap.get(name);
+ if (resource == null) {
+ throw new HyracksDataException("Resource doesn't exist");
+ }
+ id2ResourceMap.remove(name);
+ name2ResourceMap.remove(resource.getResourceId());
+ File file = new File(getFileName(mountPoints.get(0), resource.getResourceName()));
+ file.delete();
+ }
+
+ @Override
+ public List<ILocalResource> getAllResources() throws HyracksDataException {
+ // TODO Auto-generated method stub
+ return null;
+ }
+
+ private String getFileName(String mountPoint, String baseDir) {
+
+ String fileName = new String(mountPoint);
+
+ if (!fileName.endsWith(System.getProperty("file.separator"))) {
+ fileName += System.getProperty("file.separator");
+ }
+ if (!baseDir.endsWith(System.getProperty("file.separate"))) {
+ baseDir += System.getProperty("file.separator");
+ }
+ fileName += baseDir + METADATA_FILE_NAME;
+
+ return fileName;
+ }
+
+ private ILocalResource cloneResource(ILocalResource resource) {
+ switch (resource.getResourceClass().getResourceClassId()) {
+ case ILocalResourceClass.LSMBTree:
+ return new LSMBTreeLocalResource();//TODO change the constructor appropriately
+ default:
+ throw new IllegalArgumentException();
+ }
+ }
+}
diff --git a/hyracks-storage-common/src/main/java/edu/uci/ics/hyracks/storage/common/file/IndexLocalResourceRepositoryFactory.java b/hyracks-storage-common/src/main/java/edu/uci/ics/hyracks/storage/common/file/IndexLocalResourceRepositoryFactory.java
new file mode 100644
index 0000000..162709f
--- /dev/null
+++ b/hyracks-storage-common/src/main/java/edu/uci/ics/hyracks/storage/common/file/IndexLocalResourceRepositoryFactory.java
@@ -0,0 +1,11 @@
+package edu.uci.ics.hyracks.storage.common.file;
+
+public class IndexLocalResourceRepositoryFactory implements ILocalResourceRepositoryFactory {
+
+ @Override
+ public ILocalResourceRepository createRepository() {
+ // TODO Auto-generated method stub
+ return null;
+ }
+
+}
diff --git a/hyracks-storage-common/src/main/java/edu/uci/ics/hyracks/storage/common/file/LSMBTreeLocalResource.java b/hyracks-storage-common/src/main/java/edu/uci/ics/hyracks/storage/common/file/LSMBTreeLocalResource.java
new file mode 100644
index 0000000..40b6bf4
--- /dev/null
+++ b/hyracks-storage-common/src/main/java/edu/uci/ics/hyracks/storage/common/file/LSMBTreeLocalResource.java
@@ -0,0 +1,35 @@
+package edu.uci.ics.hyracks.storage.common.file;
+
+public class LSMBTreeLocalResource implements ILocalResource {
+
+ @Override
+ public byte[] toBytes() {
+ // TODO Auto-generated method stub
+ return null;
+ }
+
+ @Override
+ public long getResourceId() {
+ // TODO Auto-generated method stub
+ return 0;
+ }
+
+ @Override
+ public String getResourceName() {
+ // TODO Auto-generated method stub
+ return null;
+ }
+
+ @Override
+ public Object getResourceObject() {
+ // TODO Auto-generated method stub
+ return null;
+ }
+
+ @Override
+ public ILocalResourceClass getResourceClass() {
+ // TODO Auto-generated method stub
+ return null;
+ }
+
+}
diff --git a/hyracks-storage-common/src/main/java/edu/uci/ics/hyracks/storage/common/file/LSMBTreeLocalResourceClass.java b/hyracks-storage-common/src/main/java/edu/uci/ics/hyracks/storage/common/file/LSMBTreeLocalResourceClass.java
new file mode 100644
index 0000000..1d9913c
--- /dev/null
+++ b/hyracks-storage-common/src/main/java/edu/uci/ics/hyracks/storage/common/file/LSMBTreeLocalResourceClass.java
@@ -0,0 +1,23 @@
+package edu.uci.ics.hyracks.storage.common.file;
+
+public class LSMBTreeLocalResourceClass implements ILocalResourceClass {
+
+ @Override
+ public ILocalResource deserialize(byte[] bytes) {
+ // TODO Auto-generated method stub
+ return null;
+ }
+
+ @Override
+ public byte[] serialize(ILocalResource localResource) {
+ // TODO Auto-generated method stub
+ return null;
+ }
+
+ @Override
+ public int getResourceClassId() {
+ // TODO Auto-generated method stub
+ return 0;
+ }
+
+}