1
0
Fork 0
mirror of https://github.com/eclipse-cdt/cdt synced 2025-04-23 14:42:11 +02:00

Started dealing with version mismatches in the PDOM. When the versions mismatch, a reindex will kick off. This, of course, led to scalability problems and now only one indexer will run at a time thanks to a new indexer scheduling rule.

This commit is contained in:
Doug Schaefer 2006-04-20 15:35:58 +00:00
parent 6f2f3e37ee
commit e86d190bd3
11 changed files with 99 additions and 98 deletions

View file

@ -26,7 +26,8 @@ public class DBTest extends TestCase {
// Tests block size and simple first block // Tests block size and simple first block
File f = getTestDir().append("test1.dat").toFile(); File f = getTestDir().append("test1.dat").toFile();
f.delete(); f.delete();
Database db = new Database(f.getCanonicalPath(), 0); Database db = new Database(f.getCanonicalPath());
assertEquals(0, db.getVersion());
final int realsize = 42; final int realsize = 42;
final int blocksize = (realsize / Database.MIN_SIZE + 1) * Database.MIN_SIZE; final int blocksize = (realsize / Database.MIN_SIZE + 1) * Database.MIN_SIZE;
@ -43,7 +44,7 @@ public class DBTest extends TestCase {
// Tests free block linking // Tests free block linking
File f = getTestDir().append("test2.dat").toFile(); File f = getTestDir().append("test2.dat").toFile();
f.delete(); f.delete();
Database db = new Database(f.getCanonicalPath(), 0); Database db = new Database(f.getCanonicalPath());
final int realsize = 42; final int realsize = 42;
final int blocksize = (realsize / Database.MIN_SIZE + 1) * Database.MIN_SIZE; final int blocksize = (realsize / Database.MIN_SIZE + 1) * Database.MIN_SIZE;
@ -63,7 +64,7 @@ public class DBTest extends TestCase {
// //
File f = getTestDir().append("test2.dat").toFile(); File f = getTestDir().append("test2.dat").toFile();
f.delete(); f.delete();
Database db = new Database(f.getCanonicalPath(), 0); Database db = new Database(f.getCanonicalPath());
int mem1 = db.malloc(42); int mem1 = db.malloc(42);
db.free(mem1); db.free(mem1);
@ -101,7 +102,7 @@ public class DBTest extends TestCase {
// Tests inserting and retrieving strings // Tests inserting and retrieving strings
File f = getTestDir().append("testStrings.dat").toFile(); File f = getTestDir().append("testStrings.dat").toFile();
f.delete(); f.delete();
final Database db = new Database(f.getCanonicalPath(), 0); final Database db = new Database(f.getCanonicalPath());
String[] names = { String[] names = {
"ARLENE", "ARLENE",

View file

@ -13,16 +13,9 @@ package org.eclipse.cdt.core.browser;
import java.util.ArrayList; import java.util.ArrayList;
import java.util.Collection; import java.util.Collection;
import org.eclipse.cdt.core.CCorePlugin;
import org.eclipse.cdt.core.model.CModelException;
import org.eclipse.cdt.core.model.CoreModel;
import org.eclipse.cdt.core.model.ICElement; import org.eclipse.cdt.core.model.ICElement;
import org.eclipse.cdt.core.model.ICProject; import org.eclipse.cdt.core.model.ICProject;
import org.eclipse.cdt.core.model.IElementChangedListener;
import org.eclipse.cdt.core.model.IWorkingCopy;
import org.eclipse.cdt.internal.core.browser.util.ArrayUtil; import org.eclipse.cdt.internal.core.browser.util.ArrayUtil;
import org.eclipse.core.runtime.IProgressMonitor;
import org.eclipse.core.runtime.Preferences.IPropertyChangeListener;
/** /**
* Manages a search cache for types in the workspace. Instead of returning * Manages a search cache for types in the workspace. Instead of returning

View file

@ -13,6 +13,8 @@ package org.eclipse.cdt.core.browser;
import org.eclipse.cdt.core.model.ICProject; import org.eclipse.cdt.core.model.ICProject;
import org.eclipse.cdt.core.parser.ast.ASTAccessVisibility; import org.eclipse.cdt.core.parser.ast.ASTAccessVisibility;
import org.eclipse.cdt.internal.core.pdom.dom.PDOMBinding;
import org.eclipse.cdt.internal.core.pdom.dom.PDOMNotImplementedError;
/** /**
* @author Doug Schaefer * @author Doug Schaefer
@ -20,169 +22,144 @@ import org.eclipse.cdt.core.parser.ast.ASTAccessVisibility;
*/ */
public class PDOMTypeInfo implements ITypeInfo { public class PDOMTypeInfo implements ITypeInfo {
public void addDerivedReference(ITypeReference location) { private final PDOMBinding binding;
// TODO Auto-generated method stub private final int elementType;
public PDOMTypeInfo(PDOMBinding binding, int elementType) {
this.binding = binding;
this.elementType = elementType;
}
public void addDerivedReference(ITypeReference location) {
throw new PDOMNotImplementedError();
} }
public void addReference(ITypeReference location) { public void addReference(ITypeReference location) {
// TODO Auto-generated method stub throw new PDOMNotImplementedError();
} }
public boolean canSubstituteFor(ITypeInfo info) { public boolean canSubstituteFor(ITypeInfo info) {
// TODO Auto-generated method stub throw new PDOMNotImplementedError();
return false;
} }
public boolean encloses(ITypeInfo info) { public boolean encloses(ITypeInfo info) {
// TODO Auto-generated method stub throw new PDOMNotImplementedError();
return false;
} }
public boolean exists() { public boolean exists() {
// TODO Auto-generated method stub throw new PDOMNotImplementedError();
return false;
} }
public int getCElementType() { public int getCElementType() {
// TODO Auto-generated method stub return elementType;
return 0;
} }
public ITypeReference[] getDerivedReferences() { public ITypeReference[] getDerivedReferences() {
// TODO Auto-generated method stub throw new PDOMNotImplementedError();
return null;
} }
public ITypeInfo[] getEnclosedTypes() { public ITypeInfo[] getEnclosedTypes() {
// TODO Auto-generated method stub throw new PDOMNotImplementedError();
return null;
} }
public ITypeInfo[] getEnclosedTypes(int[] kinds) { public ITypeInfo[] getEnclosedTypes(int[] kinds) {
// TODO Auto-generated method stub throw new PDOMNotImplementedError();
return null;
} }
public ITypeInfo getEnclosingNamespace(boolean includeGlobalNamespace) { public ITypeInfo getEnclosingNamespace(boolean includeGlobalNamespace) {
// TODO Auto-generated method stub throw new PDOMNotImplementedError();
return null;
} }
public ICProject getEnclosingProject() { public ICProject getEnclosingProject() {
// TODO Auto-generated method stub throw new PDOMNotImplementedError();
return null;
} }
public ITypeInfo getEnclosingType() { public ITypeInfo getEnclosingType() {
// TODO Auto-generated method stub throw new PDOMNotImplementedError();
return null;
} }
public ITypeInfo getEnclosingType(int[] kinds) { public ITypeInfo getEnclosingType(int[] kinds) {
// TODO Auto-generated method stub throw new PDOMNotImplementedError();
return null;
} }
public String getName() { public String getName() {
// TODO Auto-generated method stub throw new PDOMNotImplementedError();
return null;
} }
public IQualifiedTypeName getQualifiedTypeName() { public IQualifiedTypeName getQualifiedTypeName() {
// TODO Auto-generated method stub throw new PDOMNotImplementedError();
return null;
} }
public ITypeReference[] getReferences() { public ITypeReference[] getReferences() {
// TODO Auto-generated method stub throw new PDOMNotImplementedError();
return null;
} }
public ITypeReference getResolvedReference() { public ITypeReference getResolvedReference() {
// TODO Auto-generated method stub throw new PDOMNotImplementedError();
return null;
} }
public ITypeInfo getRootNamespace(boolean includeGlobalNamespace) { public ITypeInfo getRootNamespace(boolean includeGlobalNamespace) {
// TODO Auto-generated method stub throw new PDOMNotImplementedError();
return null;
} }
public ITypeInfo[] getSubTypes() { public ITypeInfo[] getSubTypes() {
// TODO Auto-generated method stub throw new PDOMNotImplementedError();
return null;
} }
public ASTAccessVisibility getSuperTypeAccess(ITypeInfo subType) { public ASTAccessVisibility getSuperTypeAccess(ITypeInfo subType) {
// TODO Auto-generated method stub throw new PDOMNotImplementedError();
return null;
} }
public ITypeInfo[] getSuperTypes() { public ITypeInfo[] getSuperTypes() {
// TODO Auto-generated method stub throw new PDOMNotImplementedError();
return null;
} }
public boolean hasEnclosedTypes() { public boolean hasEnclosedTypes() {
// TODO Auto-generated method stub throw new PDOMNotImplementedError();
return false;
} }
public boolean hasSubTypes() { public boolean hasSubTypes() {
// TODO Auto-generated method stub throw new PDOMNotImplementedError();
return false;
} }
public boolean hasSuperTypes() { public boolean hasSuperTypes() {
// TODO Auto-generated method stub throw new PDOMNotImplementedError();
return false;
} }
public boolean isClass() { public boolean isClass() {
// TODO Auto-generated method stub throw new PDOMNotImplementedError();
return false;
} }
public boolean isEnclosed(ITypeInfo info) { public boolean isEnclosed(ITypeInfo info) {
// TODO Auto-generated method stub throw new PDOMNotImplementedError();
return false;
} }
public boolean isEnclosed(ITypeSearchScope scope) { public boolean isEnclosed(ITypeSearchScope scope) {
// TODO Auto-generated method stub throw new PDOMNotImplementedError();
return false;
} }
public boolean isEnclosedType() { public boolean isEnclosedType() {
// TODO Auto-generated method stub throw new PDOMNotImplementedError();
return false;
} }
public boolean isEnclosingType() { public boolean isEnclosingType() {
// TODO Auto-generated method stub throw new PDOMNotImplementedError();
return false;
} }
public boolean isReferenced(ITypeSearchScope scope) { public boolean isReferenced(ITypeSearchScope scope) {
// TODO Auto-generated method stub throw new PDOMNotImplementedError();
return false;
} }
public boolean isUndefinedType() { public boolean isUndefinedType() {
// TODO Auto-generated method stub throw new PDOMNotImplementedError();
return false;
} }
public void setCElementType(int type) { public void setCElementType(int type) {
// TODO Auto-generated method stub throw new PDOMNotImplementedError();
} }
public int compareTo(Object arg0) { public int compareTo(Object arg0) {
// TODO Auto-generated method stub throw new PDOMNotImplementedError();
return 0;
} }
} }

View file

@ -13,6 +13,7 @@ package org.eclipse.cdt.core.dom;
import org.eclipse.cdt.core.model.ICProject; import org.eclipse.cdt.core.model.ICProject;
import org.eclipse.core.runtime.CoreException; import org.eclipse.core.runtime.CoreException;
import org.eclipse.core.runtime.jobs.ISchedulingRule;
/** /**
* @author Doug Schaefer * @author Doug Schaefer
@ -31,4 +32,8 @@ public interface IPDOMManager {
public String getIndexerId(ICProject project) throws CoreException; public String getIndexerId(ICProject project) throws CoreException;
public void setIndexerId(ICProject project, String indexerId) throws CoreException; public void setIndexerId(ICProject project, String indexerId) throws CoreException;
// Scheduling rule used by indexers to make sure we don't get
// Too much indexing going on.
public ISchedulingRule getIndexerSchedulingRule();
} }

View file

@ -60,7 +60,7 @@ public class PDOM extends PlatformObject
private final IPath dbPath; private final IPath dbPath;
private Database db; private Database db;
private static final int VERSION = 0; public static final int VERSION = 1;
public static final int LINKAGES = Database.DATA_AREA; public static final int LINKAGES = Database.DATA_AREA;
public static final int FILE_INDEX = Database.DATA_AREA + 4; public static final int FILE_INDEX = Database.DATA_AREA + 4;
@ -84,9 +84,13 @@ public class PDOM extends PlatformObject
rproject.setPersistentProperty(dbNameProperty, dbName); rproject.setPersistentProperty(dbNameProperty, dbName);
} }
dbPath = CCorePlugin.getDefault().getStateLocation().append(dbName); dbPath = CCorePlugin.getDefault().getStateLocation().append(dbName);
db = new Database(dbPath.toOSString(), VERSION); db = new Database(dbPath.toOSString());
// Create the appropriate indexer // Check the version and force a rebuild if needed.
// TODO Conversion might be a nicer story down the road
if (db.getVersion() != VERSION) {
indexer.reindex();
}
} }
public Object getAdapter(Class adapter) { public Object getAdapter(Class adapter) {
@ -153,9 +157,6 @@ public class PDOM extends PlatformObject
} }
public Database getDB() throws CoreException { public Database getDB() throws CoreException {
if (db == null)
db = new Database(dbPath.toOSString(), VERSION);
return db; return db;
} }
@ -208,7 +209,9 @@ public class PDOM extends PlatformObject
} }
public void clear() throws CoreException { public void clear() throws CoreException {
getDB().clear(); Database db = getDB();
db.clear();
db.setVersion(VERSION);
fileIndex = null; fileIndex = null;
} }

View file

@ -32,6 +32,7 @@ import org.eclipse.core.runtime.IStatus;
import org.eclipse.core.runtime.Platform; import org.eclipse.core.runtime.Platform;
import org.eclipse.core.runtime.QualifiedName; import org.eclipse.core.runtime.QualifiedName;
import org.eclipse.core.runtime.Status; import org.eclipse.core.runtime.Status;
import org.eclipse.core.runtime.jobs.ISchedulingRule;
import org.eclipse.core.runtime.jobs.Job; import org.eclipse.core.runtime.jobs.Job;
import org.eclipse.core.runtime.preferences.IEclipsePreferences; import org.eclipse.core.runtime.preferences.IEclipsePreferences;
import org.eclipse.core.runtime.preferences.IPreferencesService; import org.eclipse.core.runtime.preferences.IPreferencesService;
@ -50,6 +51,15 @@ public class PDOMManager implements IPDOMManager, IElementChangedListener {
private static final QualifiedName pdomProperty private static final QualifiedName pdomProperty
= new QualifiedName(CCorePlugin.PLUGIN_ID, "pdom"); //$NON-NLS-1$ = new QualifiedName(CCorePlugin.PLUGIN_ID, "pdom"); //$NON-NLS-1$
private final ISchedulingRule indexerSchedulingRule = new ISchedulingRule() {
public boolean contains(ISchedulingRule rule) {
return rule == this;
}
public boolean isConflicting(ISchedulingRule rule) {
return rule == this;
}
};
public IPDOM getPDOM(ICProject project) { public IPDOM getPDOM(ICProject project) {
try { try {
IProject rproject = project.getProject(); IProject rproject = project.getProject();
@ -216,6 +226,10 @@ public class PDOMManager implements IPDOMManager, IElementChangedListener {
throw new CoreException(new Status(IStatus.ERROR, CCorePlugin.PLUGIN_ID, throw new CoreException(new Status(IStatus.ERROR, CCorePlugin.PLUGIN_ID,
0, CCorePlugin.getResourceString("indexer.notFound"), null)); //$NON-NLS-1$ 0, CCorePlugin.getResourceString("indexer.notFound"), null)); //$NON-NLS-1$
} }
public ISchedulingRule getIndexerSchedulingRule() {
return indexerSchedulingRule;
}
/** /**
* Startup the PDOM. This mainly sets us up to handle model * Startup the PDOM. This mainly sets us up to handle model

View file

@ -42,7 +42,7 @@ public class Database {
public static final int NEXT_OFFSET = INT_SIZE * 2; public static final int NEXT_OFFSET = INT_SIZE * 2;
public static final int DATA_AREA = CHUNK_SIZE / MIN_SIZE * INT_SIZE + INT_SIZE; public static final int DATA_AREA = CHUNK_SIZE / MIN_SIZE * INT_SIZE + INT_SIZE;
public Database(String filename, int version) throws CoreException { public Database(String filename) throws CoreException {
try { try {
file = new RandomAccessFile(filename, "rw"); //$NON-NLS-1$ file = new RandomAccessFile(filename, "rw"); //$NON-NLS-1$
@ -54,7 +54,7 @@ public class Database {
} }
toc = new Chunk[(int)nChunks]; toc = new Chunk[(int)nChunks];
init(version); init();
} catch (IOException e) { } catch (IOException e) {
throw new CoreException(new DBStatus(e)); throw new CoreException(new DBStatus(e));
} }
@ -69,14 +69,17 @@ public class Database {
} }
} }
private void init(int version) throws CoreException { private void init() throws CoreException {
// Load in the magic chunk zero // Load in the magic chunk zero
toc[0] = new Chunk(file, 0); toc[0] = new Chunk(file, 0);
int oldversion = toc[0].getInt(0); }
if (oldversion != version) {
// Conversion? public int getVersion() {
toc[0].putInt(0, version); return toc[0].getInt(0);
} }
public void setVersion(int version) {
toc[0].putInt(0, version);
} }
/** /**
@ -87,7 +90,8 @@ public class Database {
int version = toc[0].getInt(0); int version = toc[0].getInt(0);
create(); create();
toc = new Chunk[1]; toc = new Chunk[1];
init(version); init();
setVersion(version);
} }
/** /**

View file

@ -11,6 +11,7 @@
package org.eclipse.cdt.internal.core.pdom.indexer.ctags; package org.eclipse.cdt.internal.core.pdom.indexer.ctags;
import org.eclipse.cdt.core.CCorePlugin;
import org.eclipse.cdt.core.model.ICProject; import org.eclipse.cdt.core.model.ICProject;
import org.eclipse.cdt.core.model.IIncludeReference; import org.eclipse.cdt.core.model.IIncludeReference;
import org.eclipse.cdt.core.model.ISourceRoot; import org.eclipse.cdt.core.model.ISourceRoot;
@ -36,6 +37,7 @@ public class CtagsReindex extends Job {
super("ctags Indexer: " + ((PDOM)indexer.getPDOM()).getProject().getElementName()); super("ctags Indexer: " + ((PDOM)indexer.getPDOM()).getProject().getElementName());
this.indexer = indexer; this.indexer = indexer;
this.pdom = (PDOM)indexer.getPDOM(); this.pdom = (PDOM)indexer.getPDOM();
setRule(CCorePlugin.getPDOMManager().getIndexerSchedulingRule());
} }
protected IStatus run(IProgressMonitor monitor) { protected IStatus run(IProgressMonitor monitor) {

View file

@ -39,8 +39,9 @@ class PDOMFastHandleDelta extends PDOMFastIndexerJob {
private List removedTUs; private List removedTUs;
public PDOMFastHandleDelta(PDOM pdom, ICElementDelta delta) { public PDOMFastHandleDelta(PDOM pdom, ICElementDelta delta) {
super("Delta Handler", pdom); super(pdom);
this.delta = delta; this.delta = delta;
setRule(CCorePlugin.getPDOMManager().getIndexerSchedulingRule());
} }
protected IStatus run(IProgressMonitor monitor) { protected IStatus run(IProgressMonitor monitor) {

View file

@ -11,7 +11,7 @@
package org.eclipse.cdt.internal.core.pdom.indexer.fast; package org.eclipse.cdt.internal.core.pdom.indexer.fast;
import org.eclipse.cdt.core.dom.ast.IASTPreprocessorIncludeStatement; import org.eclipse.cdt.core.CCorePlugin;
import org.eclipse.cdt.core.dom.ast.IASTTranslationUnit; import org.eclipse.cdt.core.dom.ast.IASTTranslationUnit;
import org.eclipse.cdt.core.model.ILanguage; import org.eclipse.cdt.core.model.ILanguage;
import org.eclipse.cdt.core.model.ITranslationUnit; import org.eclipse.cdt.core.model.ITranslationUnit;
@ -27,9 +27,10 @@ public abstract class PDOMFastIndexerJob extends Job {
protected final PDOM pdom; protected final PDOM pdom;
public PDOMFastIndexerJob(String name, PDOM pdom) { public PDOMFastIndexerJob(PDOM pdom) {
super(name); super("Fast Indexer: " + pdom.getProject().getElementName());
this.pdom = pdom; this.pdom = pdom;
setRule(CCorePlugin.getPDOMManager().getIndexerSchedulingRule());
} }
protected void addTU(ITranslationUnit tu) throws InterruptedException, CoreException { protected void addTU(ITranslationUnit tu) throws InterruptedException, CoreException {

View file

@ -37,7 +37,7 @@ import org.eclipse.core.runtime.content.IContentType;
public class PDOMFastReindex extends PDOMFastIndexerJob { public class PDOMFastReindex extends PDOMFastIndexerJob {
public PDOMFastReindex(PDOM pdom) { public PDOMFastReindex(PDOM pdom) {
super("Reindex", pdom); super(pdom);
} }
protected IStatus run(IProgressMonitor monitor) { protected IStatus run(IProgressMonitor monitor) {