Repository navigation
Description
Motivation
While investigating an elasticsearch app I felt that core should provide an API to asynchronously notify apps of file changes.
Currently search_lucene implements such a mechanism itself to not slow down file writes by indexing them in the post write hook. Instead the file is flagged as updated in the oc_lucene_status table. The files are indexed in a backgroundjob that also uses this status table to remember skipped files or indexing errors.
I plan to use the same mechanism for elasticsearch and extend the status table with a message column, so the error message can be reported to the user. An icon next to the fileactions with the message as title should suffice if the user can then trigger a rescan.
Other apps could use the same mechanism:
- gallery could prerender not existing thumbnails in the background, until we reuse
- the previw generation mechanism could create previews with a cron job
- music could extract metadata, cc @MorrisJobke
- activity could send emails asynchronously, cc @nickvergessen
- any app that does not neet its file actions to be atomic with the file cache
Furthermore, the apps should be able to act immediately when a file is uploaded via the web frontend. When encryption is enabled that is the only time when apps can access the users files because he needs to be logged in.
Implementation
I would use a new oc_filestatus table with (fileid, app, status, message). When apps register to be notified of async file changes they will be called in a background job and can then set the status to their liking. Search_lucene currently uses
const STATUS_NEW = 'N';
const STATUS_INDEXED = 'I';
const STATUS_SKIPPED = 'S';
const STATUS_UNINDEXED = 'U';
const STATUS_VANISHED = 'V';
const STATUS_ERROR = 'E';I don't recommend using ints or booleans in the database. It makes manual migrations harder than necessary. Indexes speed up chars and human readable strings just as well.
Activity
nickvergessen commentedon Nov 7, 2014
The activity app does NOT send emails synchronously. It has a table where the potential emails are stored, which are then send asynchronously with a background job.
(Just saying this to make sure that no one gets this wrong, not saying that the idea here is good/bad)
LukasReschke commentedon Nov 7, 2014
Ref #11685
butonic commentedon Nov 7, 2014
@nickvergessen I was not implying the activity ap was doing it in sync. Interesting that you kind of built an async status mechanism as well.
MorrisJobke commentedon Nov 7, 2014
I remind the discussion about async hooks as well. Maybe this is also a valid way to solve the issue, that approach wants to fix.
bantu commentedon Nov 10, 2014
From a performance perspective having application specific tables like
oc_lucene_statusis probably better than having a single and genericoc_filestatustable.Also, from a data perspective there does not seem to be any useful operation you could do on a table like
oc_filestatus. A query like "give me all files with status = 1" does not make sense because 1 can mean A in app X and B in app Y. Furthermore, an application might just need another column to store additonal data.butonic commentedon Nov 17, 2014
The reason for a generic table is derived from the roquirement of several apps having to do the same thing: async file operations. Instead of every app having to implement it's own mechanism, core should have an API for that.
A query like "give me all files with status = N" may actually mak sense: a background job could fetch all NEW files and hand the ids over to the apps that registered for that change. That is what the
appcolumn is for.DeepDiver1975 commentedon Nov 21, 2014
From my understanding we need to move away from the database and model this on pure interface layer to allow maximum integration of any kind - e.g. storing file is pointless in an customized environment where no cache is used. Yes - real rare and extreme case - but this exists.
Further more having an interface for pushing jobs we gain the possibility to use queuing systems for execution (e.g. WhatEverCoolMQ)
karlitschek commentedon Nov 21, 2014
@MTRichards So we have the first guy who wants to use this in a real life scenario. Maybe it´s helpful to design this the right way.
We have a CLI tool that runs on the same server. ownCloud should call this tool once a new file is uploaded. Once the file is "processed" by the CLI tool the tool could call some kind of ownCloud API to inject the processed file into the normal ownCloud workflow again.
I hope this helps to design the system
MTRichards commentedon Nov 21, 2014
Precisely. The workflow would look like this:
Make sense?
butonic commentedon Nov 24, 2014
I think @dragotin can also add a few insights on Async file opload from the desktop/sync perspective.
dragotin commentedon Nov 25, 2014
Async file upload is discussed here: #12024 but as I read this it is not really the same.
I think the proposed solution here is a bit too simple. It will drive us into another layer of problems. Imagine this scenario, let's create an example where we use this to calculate checksums of a file.
That is a problem, as the process can stack up. And also I don't think that scales, especially things like thumbnail generation or checksums tend to pile up load. So I think another design goal should be to be able to schedule the requests, ie. through a priority. For example, thumbnail generation might run with a lower priority than a checksum calculator.
I hate to say the word, but maybe we need a daemon that maintains a list of running processes, can kill already running jobs and start a new one. Also, it should be able to do a poor mans scheduling.
DeepDiver1975 commentedon Nov 25, 2014
A daemon has the issue of being a bottleneck and single point of failure. An appropriate architecture which is scalable and fault tolerant would be a queing system.
Please no more self written database kungfu to write status flags of jobs - search for yourself regarding 'database job queue anti pattern'
butonic commentedon Nov 25, 2014
Related: #12097
10 remaining items
DeepDiver1975 commentedon Dec 9, 2014
http://laravel.com/docs/4.2/queues looks pretty promising as php queue implementation to use job queues. In case no queuing system is available the jobs are executed synchronous - we gain nothing in this case but add the necessary flexibility and scalability in bigger installations.
DeepDiver1975 commentedon Dec 9, 2014
we have been thinking about this as well - e.g. in the area of chunked upload or upload to external storage. As soon as the upload to the owncloud server is finished the response is sent back to the client and further processing is handled by the job queue. Until the operation was finally executed the file is presented via webdav but any file operation is not permitted - webdav locking support seems legitimate for this purpose.
@guruz @dragotin
butonic commentedon Dec 9, 2014
DeepDiver1975 commentedon Jan 15, 2015
interesting for small internet installation is the use of Iron.io together with the push queue concept - http://laravel.com/docs/4.2/queues#push-queues
basically iron.io pushes back the job to the instance via http to a special route - sounds like a reasonable approach for the non-enterprise installations aka web hosters etc.
DeepDiver1975 commentedon Feb 10, 2015
available via packagist - https://packagist.org/packages/illuminate/queue
ownclouders commentedon Jan 13, 2018
Hey, this issue has been closed because the label
status/STALEis set and there were no updates for 7 days. Feel free to reopen this issue if you deem it appropriate.(This is an automated comment from GitMate.io.)