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

View file

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

View file

@ -13,6 +13,7 @@ package org.eclipse.cdt.core.dom;
import org.eclipse.cdt.core.model.ICProject;
import org.eclipse.core.runtime.CoreException;
import org.eclipse.core.runtime.jobs.ISchedulingRule;
/**
* @author Doug Schaefer
@ -31,4 +32,8 @@ public interface IPDOMManager {
public String getIndexerId(ICProject project) 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 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 FILE_INDEX = Database.DATA_AREA + 4;
@ -84,9 +84,13 @@ public class PDOM extends PlatformObject
rproject.setPersistentProperty(dbNameProperty, 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) {
@ -153,9 +157,6 @@ public class PDOM extends PlatformObject
}
public Database getDB() throws CoreException {
if (db == null)
db = new Database(dbPath.toOSString(), VERSION);
return db;
}
@ -208,7 +209,9 @@ public class PDOM extends PlatformObject
}
public void clear() throws CoreException {
getDB().clear();
Database db = getDB();
db.clear();
db.setVersion(VERSION);
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.QualifiedName;
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.preferences.IEclipsePreferences;
import org.eclipse.core.runtime.preferences.IPreferencesService;
@ -50,6 +51,15 @@ public class PDOMManager implements IPDOMManager, IElementChangedListener {
private static final QualifiedName pdomProperty
= 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) {
try {
IProject rproject = project.getProject();
@ -217,6 +227,10 @@ public class PDOMManager implements IPDOMManager, IElementChangedListener {
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
* change events.

View file

@ -42,7 +42,7 @@ public class Database {
public static final int NEXT_OFFSET = INT_SIZE * 2;
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 {
file = new RandomAccessFile(filename, "rw"); //$NON-NLS-1$
@ -54,7 +54,7 @@ public class Database {
}
toc = new Chunk[(int)nChunks];
init(version);
init();
} catch (IOException 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
toc[0] = new Chunk(file, 0);
int oldversion = toc[0].getInt(0);
if (oldversion != version) {
// Conversion?
toc[0].putInt(0, version);
}
public int getVersion() {
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);
create();
toc = new Chunk[1];
init(version);
init();
setVersion(version);
}
/**

View file

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

View file

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

View file

@ -11,7 +11,7 @@
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.model.ILanguage;
import org.eclipse.cdt.core.model.ITranslationUnit;
@ -27,9 +27,10 @@ public abstract class PDOMFastIndexerJob extends Job {
protected final PDOM pdom;
public PDOMFastIndexerJob(String name, PDOM pdom) {
super(name);
public PDOMFastIndexerJob(PDOM pdom) {
super("Fast Indexer: " + pdom.getProject().getElementName());
this.pdom = pdom;
setRule(CCorePlugin.getPDOMManager().getIndexerSchedulingRule());
}
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 PDOMFastReindex(PDOM pdom) {
super("Reindex", pdom);
super(pdom);
}
protected IStatus run(IProgressMonitor monitor) {