Comments (4)
Yup, definitely. I have some ideas on supporting transactions over REST. Let's talk on IRC and make up a draft for nano/Txn :)
from nano.
I'd love to be in on this as well.
from nano.
I think we had best discuss it here, in public. I'll start off with brainstorming of ideas.
I guess the first concern is that Txn might be a little bit conceptually difficult for new users, for two reasons:
- It requires you to write code like libraries: receive a callback and call it exactly once, with optional error objects (which you must never throw)
- Txn requires two callbacks which can be a bit odd-looking in the source code
Next, my concern is conceptual misunderstanding.
- Primarily, instead of having a document and doing something with it, you have an ID and you react to whatever the content happens to be. That is how Txn can retry several times, it re-runs your function, which may have completely different behavior from run to run (as the doc changes)
- On the other hand, a major exception that I use a ton is hinting the doc contents to Txn, to skipping the first fetch. Obviously this is really nice for a
_changes
workflow- Query
_changes?include_docs=true
- When you get an event, you already know the doc and thus
_id
and_rev
- Try a "claim the job" transaction
txn({max_tries:1, after:Math.random(), doc:change.doc}, ...)
With max_tries=1, this is basically a normal doc update after a random delay. (The random delay means you can run many identical copies of this code.)- The operation function just sets
doc.pending = true; doc.expires_at = new Date + 5000
- If the transaction fails, ignore it. Somebody else got it and you will see it again soon.
- If the transaction succeeds, run another transaction to do the real job.
- Query
That is pretty cool and I am using something like this in some places, however:
- That seems a bit complicated, perhaps it could be simplified and implemented inside Txn or Nano.
- It is not a general job queue, If the worker crashes, it will never update the doc again, but you have already ignored it. So that job will be incomplete forever (or until you start a new worker from scratch). This is exactly why I moved to CQS for jobs. Still, some _changes tools would probably help the community.
The final note is that I am still not a regular Nano user (still waiting on that next big couch client project)
from nano.
I didn't get the time to review Txn yet but these are so far my overall thoughts on transactions:
- There's no space in
nano
for transactional code. So importing a library likeTxn
would be ideal.nano
should be clean and feel like a introduction to the CouchDB API via code. Keeping things minimal and working with each other is awesome and desirable. - CouchDB supports transactional insert of a set of documents (bulk upload). However it's possible that Couch accepts some updates and not others, so these should be possible to rollback. (am I wrong here?)
- CouchDB allows bulk deletes but with the some restrictions.
nano
should allow doing this while keeping ACID semantics, if possible- It is desirable that you can mix inserts and deletes in a single statement.
- It is desirable that you can do property level updates on CouchDB. This is something like I envision on implementing transactions over REST. Responsibility would have to be on the client side cause server does not deal with this.
function update_user(gh) {
db.view( ''users", "by_github_account", {key: gh.id})
.increment('version', 1)
.replace('github_login', gh.login)
.replace('github', gh.user)
.delete('linkedin.deletemeplease')
.rename('meeutp','meetup')
.push('anarray', 1) // should also include security stuff
.save(
function save_cb(e) {
if(e) {
console.log("Couldn't update ");
return;
}
console.log(gh.id + " updated");
return;
});
};
This should look a lot better than this but would be cool to be able to do something like this.
I'll revisit the issue after I check out Txn later this week :)
from nano.
Related Issues (20)
- Does nano support purge? HOT 2
- db.attachment.get file- 'could not be opened because it is empty'
- Can not get correct userctx HOT 2
- Couch DB 2 compatibilty HOT 3
- bulk() with _deleted:true causes error HOT 3
- db.multipart.get does not work with Cloudant Local 1.0.0.5 HOT 1
- Enable permanent replication by writing to "_replicator" database instead of "_replicate" database. HOT 3
- Support temp view
- Doubt on db access of live app HOT 2
- What is the keys in view function based on? Is it the key you emit in the views/map function? HOT 1
- How do you update _rev to update a document?
- uploaded files displaying base64 data in the browser (attachments not viewable)
- Problem with OR -clauses? HOT 1
- Error: badarg every few hours
- Error: {error,emfile} HOT 1
- Example Lazy Creation of View
- Query string encoded when using array of keys
- Database permissions
- db.fetch array of id error
- Attempting to return simple list of documents, small issue
Recommend Projects
-
React
A declarative, efficient, and flexible JavaScript library for building user interfaces.
-
Vue.js
🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.
-
Typescript
TypeScript is a superset of JavaScript that compiles to clean JavaScript output.
-
TensorFlow
An Open Source Machine Learning Framework for Everyone
-
Django
The Web framework for perfectionists with deadlines.
-
Laravel
A PHP framework for web artisans
-
D3
Bring data to life with SVG, Canvas and HTML. 📊📈🎉
-
Recommend Topics
-
javascript
JavaScript (JS) is a lightweight interpreted programming language with first-class functions.
-
web
Some thing interesting about web. New door for the world.
-
server
A server is a program made to process requests and deliver data to clients.
-
Machine learning
Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.
-
Visualization
Some thing interesting about visualization, use data art
-
Game
Some thing interesting about game, make everyone happy.
Recommend Org
-
Facebook
We are working to build community through open source technology. NB: members must have two-factor auth.
-
Microsoft
Open source projects and samples from Microsoft.
-
Google
Google ❤️ Open Source for everyone.
-
Alibaba
Alibaba Open Source for everyone
-
D3
Data-Driven Documents codes.
-
Tencent
China tencent open source team.
from nano.