Author: rareddy
Date: 2010-11-30 13:55:44 -0500 (Tue, 30 Nov 2010)
New Revision: 2749
Modified:
branches/7.1.x/runtime/src/main/java/org/teiid/deployers/ObjectSerializer.java
branches/7.1.x/runtime/src/main/java/org/teiid/deployers/VDBDeployer.java
branches/7.1.x/runtime/src/main/java/org/teiid/deployers/VDBParserDeployer.java
Log:
TEIID-1380: Based on the last modified time of the VDB file, the old serialized metadata
file will be deleted if the VDB file is updated during server shutdown.
Modified: branches/7.1.x/runtime/src/main/java/org/teiid/deployers/ObjectSerializer.java
===================================================================
---
branches/7.1.x/runtime/src/main/java/org/teiid/deployers/ObjectSerializer.java 2010-11-30
09:03:48 UTC (rev 2748)
+++
branches/7.1.x/runtime/src/main/java/org/teiid/deployers/ObjectSerializer.java 2010-11-30
18:55:44 UTC (rev 2749)
@@ -80,6 +80,10 @@
}
}
+ public boolean isStale(File cacheFile, long timeAfter) {
+ return (cacheFile.exists() && timeAfter > cacheFile.lastModified());
+ }
+
public void removeAttachments(VFSDeploymentUnit vf) {
String dirName = baseDirectory(vf);
FileUtils.removeDirectoryAndChildren(new File(dirName));
Modified: branches/7.1.x/runtime/src/main/java/org/teiid/deployers/VDBDeployer.java
===================================================================
--- branches/7.1.x/runtime/src/main/java/org/teiid/deployers/VDBDeployer.java 2010-11-30
09:03:48 UTC (rev 2748)
+++ branches/7.1.x/runtime/src/main/java/org/teiid/deployers/VDBDeployer.java 2010-11-30
18:55:44 UTC (rev 2749)
@@ -43,7 +43,6 @@
import org.teiid.adminapi.impl.VDBMetaData;
import org.teiid.adminapi.impl.VDBTranslatorMetaData;
import org.teiid.adminapi.impl.ModelMetaData.ValidationError;
-import org.teiid.core.util.FileUtils;
import org.teiid.dqp.internal.datamgr.ConnectorManager;
import org.teiid.dqp.internal.datamgr.ConnectorManagerRepository;
import org.teiid.dqp.internal.datamgr.TranslatorRepository;
@@ -236,7 +235,7 @@
deployment.setRemoved(true);
try {
- deleteMetadataStore((VFSDeploymentUnit)unit, deployment);
+ deleteMetadataStore((VFSDeploymentUnit)unit);
} catch (IOException e) {
LogManager.logWarning(LogConstants.CTX_RUNTIME,
RuntimePlugin.Util.getString("vdb_delete_failed", e.getMessage()));
//$NON-NLS-1$
}
@@ -249,18 +248,17 @@
}
private void saveMetadataStore(VFSDeploymentUnit unit, VDBMetaData vdb,
MetadataStoreGroup store) throws IOException {
- File cacheFileName = this.serializer.getAttachmentPath(unit,
vdb.getName()+"_"+vdb.getVersion()); //$NON-NLS-1$
+ File cacheFileName = buildCachedVDBFileName(this.serializer, unit, vdb);
if (!cacheFileName.exists()) {
this.serializer.saveAttachment(cacheFileName,store);
- }
+ LogManager.logTrace(LogConstants.CTX_RUNTIME, "VDB
"+unit.getRoot().getName()+" metadata has been cached to "+ cacheFileName);
//$NON-NLS-1$ //$NON-NLS-2$
+ }
}
- private void deleteMetadataStore(VFSDeploymentUnit unit, VDBMetaData vdb) throws
IOException {
+ private void deleteMetadataStore(VFSDeploymentUnit unit) throws IOException {
if (!unit.getRoot().exists() || !shutdownListener.isShutdownInProgress()) {
- File cacheFileName = this.serializer.getAttachmentPath(unit,
vdb.getName()+"_"+vdb.getVersion()); //$NON-NLS-1$
- if (cacheFileName.exists()) {
- FileUtils.removeDirectoryAndChildren(cacheFileName.getParentFile());
- }
+ this.serializer.removeAttachments(unit);
+ LogManager.logTrace(LogConstants.CTX_RUNTIME, "VDB
"+unit.getRoot().getName()+" metadata removed"); //$NON-NLS-1$
//$NON-NLS-2$
}
}
@@ -273,7 +271,7 @@
}
final boolean cache =
"cached".equalsIgnoreCase(vdb.getPropertyValue("UseConnectorMetadata"));
//$NON-NLS-1$ //$NON-NLS-2$
- final File cacheFile = buildCachedFileName(unit, vdb, model.getName());
+ final File cacheFile = buildCachedModelFileName(unit, vdb, model.getName());
boolean loaded = false;
if (cache) {
MetadataStore store = this.serializer.loadSafe(cacheFile, MetadataStore.class);
@@ -346,10 +344,14 @@
}
}
- private File buildCachedFileName(VFSDeploymentUnit unit, VDBMetaData vdb, String
modelName) {
+ private File buildCachedModelFileName(VFSDeploymentUnit unit, VDBMetaData vdb, String
modelName) {
return this.serializer.getAttachmentPath(unit,
vdb.getName()+"_"+vdb.getVersion()+"_"+modelName); //$NON-NLS-1$
//$NON-NLS-2$
}
+ static File buildCachedVDBFileName(ObjectSerializer serializer, VFSDeploymentUnit unit,
VDBMetaData vdb) {
+ return serializer.getAttachmentPath(unit,
vdb.getName()+"_"+vdb.getVersion()); //$NON-NLS-1$
+ }
+
public void setTranslatorRepository(TranslatorRepository repo) {
this.translatorRepository = repo;
}
Modified: branches/7.1.x/runtime/src/main/java/org/teiid/deployers/VDBParserDeployer.java
===================================================================
---
branches/7.1.x/runtime/src/main/java/org/teiid/deployers/VDBParserDeployer.java 2010-11-30
09:03:48 UTC (rev 2748)
+++
branches/7.1.x/runtime/src/main/java/org/teiid/deployers/VDBParserDeployer.java 2010-11-30
18:55:44 UTC (rev 2749)
@@ -142,12 +142,21 @@
unit.addAttachment(IndexMetadataFactory.class, imf);
// add the cached store.
- File cacheFile = this.serializer.getAttachmentPath(unit,
vdb.getName()+"_"+vdb.getVersion()); //$NON-NLS-1$
+ File cacheFile = VDBDeployer.buildCachedVDBFileName(this.serializer, unit, vdb);
+ // check to see if the vdb has been modified when server is down; if it is then clear
the old files
+ if (this.serializer.isStale(cacheFile, unit.getRoot().getLastModified())) {
+ this.serializer.removeAttachments(unit);
+ LogManager.logTrace(LogConstants.CTX_RUNTIME, "VDB
"+unit.getRoot().getName()+" old cached metadata has been removed");
//$NON-NLS-1$ //$NON-NLS-2$
+ }
MetadataStoreGroup stores = this.serializer.loadSafe(cacheFile,
MetadataStoreGroup.class);
- if (stores == null) {
+ if (stores == null) {
+ // start to build the new metadata
stores = new MetadataStoreGroup();
stores.addStore(imf.getMetadataStore(vdbRepository.getSystemStore().getDatatypes()));
}
+ else {
+ LogManager.logTrace(LogConstants.CTX_RUNTIME, "VDB
"+unit.getRoot().getName()+" has being loaded from cached metadata");
//$NON-NLS-1$ //$NON-NLS-2$
+ }
unit.addAttachment(MetadataStoreGroup.class, stores);
}