Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Cache not validating due to missing txnId #325

Open
falcon027 opened this issue Jan 27, 2025 · 0 comments
Open

Cache not validating due to missing txnId #325

falcon027 opened this issue Jan 27, 2025 · 0 comments

Comments

@falcon027
Copy link
Contributor

falcon027 commented Jan 27, 2025

I just ran into a strange problem where the cache is not validated properly and I get an outdated value returned. I must have misconfigured something because the cache entries "txnId" is not set, so the validation with the contents of the memory is skipped.

In the code below you can see that if "txnId" is not set, the validation is skipped. Does anyone have an idea how to prevent the txnId from being lost?

get(id, options) {
			let value;
			if (this.cache.validated) {
				let entry = this.cache.get(id);
				if (entry) {
					let cachedValue = entry.value;
					if (entry.txnId != null) {  //     <====== entry.txnId is undefined
						value = super.get(id, {
							ifNotTxnId: entry.txnId,
							transaction: options && options.transaction,
						});
						if (value === UNMODIFIED) return cachedValue;
					} // with no txn id we do not validate; this is the state of a cached value after a write before it transacts
					else return cachedValue;    //     <====== because entry.txnId is undefined i get a outdated value from the cache          
				} else value = super.get(id, options);
			} else if (options && options.transaction) {
				return super.get(id, options);
			} else {
				value = this.cache.getValue(id);
				if (value !== undefined) {
					return value;
				}
				value = super.get(id);
			}
			if (
				value &&
				typeof value === 'object' &&
				!options &&
				typeof id !== 'object'
			) {
				let entry = this.cache.setValue(id, value, this.lastSize >> 10);
				if (this.useVersions) {
					entry.version = getLastVersion();
				}
				if (this.cache.validated) entry.txnId = getLastTxnId();
			}
			return value;
		}

Not sure if this helps but here are my database settings:

   let newObject = open({
        path: objectsPath,
        compression: false,
        dupSort: false,
        cache: {
            validated: true,
            clearKeptInterval: 100,
            cacheSize: 200
        },
        maxDbs: 1,
        eventTurnBatching: true,
        txnStartThreshold: 5,
        commitDelay: 0, 
        noMemInit: true, 
        keyEncoding: "ordered-binary",
        remapChunks: false,
        pageSize: 16384,
        useWritemap: false, 
        safeRestore: true,
        maxReaders: 100,
        encoding: "json",
    });

Thanks in advance for your help.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

1 participant