<feed xmlns='http://www.w3.org/2005/Atom'>
<title>delta/couchdb.git/src/couch_replicator/priv, branch devnode-boot-script</title>
<subtitle>github.com: apache/couchdb.git
</subtitle>
<link rel='alternate' type='text/html' href='http://trove.baserock.org/cgit/delta/couchdb.git/'/>
<entry>
<title>Update backend replicator modules</title>
<updated>2020-09-15T20:13:46+00:00</updated>
<author>
<name>Nick Vatamaniuc</name>
<email>vatamane@apache.org</email>
</author>
<published>2020-08-28T08:35:07+00:00</published>
<link rel='alternate' type='text/html' href='http://trove.baserock.org/cgit/delta/couchdb.git/commit/?id=7dd18993f25b107db05a9e99e01770c7f84bd33b'/>
<id>7dd18993f25b107db05a9e99e01770c7f84bd33b</id>
<content type='text'>
Backend replicator modules execute replication jobs. The two main modules
reponsible for job management and execution are `couch_replicator_job` and
`couch_replicator_job_server`.

`couch_replicator_job`

 - Is the main process of each replication job. When this process starts, it
   waits in the `couch_jobs:accept/2` call. This may take an indefinite amount
   of time. The spawned `couch_replicator_job` waiting in accept like that is
   called internally an "acceptor". The main pattern of execution is multiple
   acceptors are started, and after some of them accept jobs, they become
   "workers".

 - After it accepts a job, it parses the `couch_jobs` job data, which contains
   the `Rep` object and calculates the replication ID from it. Replication ID
   calculation may involve making a call to the source endpoint in order to
   fetch the contents of the javascript filter. Then, the `Rep` object and the
   replication ID is used to construct the internal `#rep_state{}` state record
   of the `gen_server`.

 - Multiple replication jobs may end up trying to run the same replication
   (with the same replication ID) concurrently. To manage these types of
   colisions, `check_ownership/3` function is called to determine if the
   current replication is the correct `owner` of that replication. If it is
   not, then the job maybe fail and exit.

 - There is a periodic checkpoint timer which sends a `checkpoint` message. The
   checkpoint frequency is calculated as the minimum of the `couch_jobs`
   activity timeout and the configured checkpoint interval. During each
   checkpoint attempt, there is a call to `couch_jobs:update/3` which updates
   the job's data with latest state and ensure the job doesn't get re-enqueued
   due to inactivity.

 - If the job completes, then `couch_jobs:finish/3` is called and the
   replication process exits `normal`. If the job crashes, there is a
   consecutive error count field (`?ERROR_COUNT`) which, is used to calculate
   the backoff penalty. There is an exponential backoff schedule, that starts
   with the base value, then doubles, but only up to a maximum value. Both the
   base and the maximum values are configurable with the
   `min_backoff_penalty_sec` and `max_backoff_penalty_sec` settings
   respecively. This is an improvement from before where the users could only
   influence the maximum backoff penalty by reducing the number of failed
   events kept by each job.

`couch_replicator_server`

 - This is a module which spawns and keeps track of `couch_replicator_job`
   processes.

 - Periodically, every `interval_sec` seconds, it runs the `reschedule` function
   which checks for pending jobs. If they are some, it will start acceptors to
   run them. If those acceptors become workers, and if the total number of
   workers goes above the `max_jobs` setting, the oldest `continuous` workers
   will be stopped until the total number of jobs falls below `max_jobs` value.

 - In addition to `max_jobs` limit, there is a `max_churn` limit which
   determines up to how many job starts to allow during each scheduling
   interval. As jobs are started, they reduce the available churn "budget" for
   that cycle and after it goes below 0 no more jobs can start until the next
   cycle.

 - This module also performs transient job cleanup. After transient jobs stop
   running previously they simply vanished but with this update they maybe
   linger for at least `transient_job_max_age_sec` seconds.
</content>
<content type='xhtml'>
<div xmlns='http://www.w3.org/1999/xhtml'>
<pre>
Backend replicator modules execute replication jobs. The two main modules
reponsible for job management and execution are `couch_replicator_job` and
`couch_replicator_job_server`.

`couch_replicator_job`

 - Is the main process of each replication job. When this process starts, it
   waits in the `couch_jobs:accept/2` call. This may take an indefinite amount
   of time. The spawned `couch_replicator_job` waiting in accept like that is
   called internally an "acceptor". The main pattern of execution is multiple
   acceptors are started, and after some of them accept jobs, they become
   "workers".

 - After it accepts a job, it parses the `couch_jobs` job data, which contains
   the `Rep` object and calculates the replication ID from it. Replication ID
   calculation may involve making a call to the source endpoint in order to
   fetch the contents of the javascript filter. Then, the `Rep` object and the
   replication ID is used to construct the internal `#rep_state{}` state record
   of the `gen_server`.

 - Multiple replication jobs may end up trying to run the same replication
   (with the same replication ID) concurrently. To manage these types of
   colisions, `check_ownership/3` function is called to determine if the
   current replication is the correct `owner` of that replication. If it is
   not, then the job maybe fail and exit.

 - There is a periodic checkpoint timer which sends a `checkpoint` message. The
   checkpoint frequency is calculated as the minimum of the `couch_jobs`
   activity timeout and the configured checkpoint interval. During each
   checkpoint attempt, there is a call to `couch_jobs:update/3` which updates
   the job's data with latest state and ensure the job doesn't get re-enqueued
   due to inactivity.

 - If the job completes, then `couch_jobs:finish/3` is called and the
   replication process exits `normal`. If the job crashes, there is a
   consecutive error count field (`?ERROR_COUNT`) which, is used to calculate
   the backoff penalty. There is an exponential backoff schedule, that starts
   with the base value, then doubles, but only up to a maximum value. Both the
   base and the maximum values are configurable with the
   `min_backoff_penalty_sec` and `max_backoff_penalty_sec` settings
   respecively. This is an improvement from before where the users could only
   influence the maximum backoff penalty by reducing the number of failed
   events kept by each job.

`couch_replicator_server`

 - This is a module which spawns and keeps track of `couch_replicator_job`
   processes.

 - Periodically, every `interval_sec` seconds, it runs the `reschedule` function
   which checks for pending jobs. If they are some, it will start acceptors to
   run them. If those acceptors become workers, and if the total number of
   workers goes above the `max_jobs` setting, the oldest `continuous` workers
   will be stopped until the total number of jobs falls below `max_jobs` value.

 - In addition to `max_jobs` limit, there is a `max_churn` limit which
   determines up to how many job starts to allow during each scheduling
   interval. As jobs are started, they reduce the available churn "budget" for
   that cycle and after it goes below 0 no more jobs can start until the next
   cycle.

 - This module also performs transient job cleanup. After transient jobs stop
   running previously they simply vanished but with this update they maybe
   linger for at least `transient_job_max_age_sec` seconds.
</pre>
</div>
</content>
</entry>
<entry>
<title>Stitch scheduling replicator together.</title>
<updated>2017-04-28T21:35:50+00:00</updated>
<author>
<name>Nick Vatamaniuc</name>
<email>vatamane@apache.org</email>
</author>
<published>2016-11-25T16:47:56+00:00</published>
<link rel='alternate' type='text/html' href='http://trove.baserock.org/cgit/delta/couchdb.git/commit/?id=4841774575fb5771a245e5f046a26eaa7ac8dbb4'/>
<id>4841774575fb5771a245e5f046a26eaa7ac8dbb4</id>
<content type='text'>
Glue together all the scheduling replicator pieces.

Scheduler is the main component. It can run a large number of replication jobs
by switching between them, stopping and starting some periodically. Jobs
which fail are backed off exponentially. Normal (non-continuous) jobs will be
allowed to run to completion to preserve their current semantics.

Scheduler behavior can configured by these configuration options in
`[replicator]` sections:

 * `max_jobs` : Number of actively running replications. Making this too high
 could cause performance issues. Making it too low could mean replications jobs
 might not have enough time to make progress before getting unscheduled again.
 This parameter can be adjusted at runtime and will take effect during next
 reschudling cycle.

 * `interval` : Scheduling interval in milliseconds. During each reschedule
 cycle scheduler might start or stop up to "max_churn" number of jobs.

 * `max_churn` : Maximum number of replications to start and stop during
 rescheduling. This parameter along with "interval" defines the rate of job
 replacement. During startup, however a much larger number of jobs could be
 started (up to max_jobs) in short period of time.

Replication jobs are added to the scheduler by the document processor or from
the `couch_replicator:replicate/2` function when called from `_replicate` HTTP
endpoint handler.

Document processor listens for updates via couch_mutlidb_changes module then
tries to add replication jobs to the scheduler. Sometimes translating a
document update to a replication job could fail, either permantly (if document
is malformed and missing some expected fields for example) or temporarily if
it is a filtered replication and filter cannot be fetched. A failed filter
fetch will be retried with an exponential backoff.

couch_replicator_clustering is in charge of monitoring cluster membership
changes. When membership changes, after a configurable quiet period, a rescan
will be initiated. Rescan will shufle replication jobs to make sure a
replication job is running on only one node.

A new set of stats were added to introspect scheduler and doc processor
internals.

The top replication supervisor structure is `rest_for_one`. This means if
a child crashes, all children to the "right" of it will be restarted (if
visualized supervisor hierarchy as an upside-down tree). Clustering,
connection pool and rate limiter are towards the "left" as they are more
fundamental, if clustering child crashes, most other components will be
restart. Doc process or and multi-db changes children are towards the "right".
If they crash, they can be safely restarted without affecting already running
replication or components like clustering or connection pool.

Jira: COUCHDB-3324
</content>
<content type='xhtml'>
<div xmlns='http://www.w3.org/1999/xhtml'>
<pre>
Glue together all the scheduling replicator pieces.

Scheduler is the main component. It can run a large number of replication jobs
by switching between them, stopping and starting some periodically. Jobs
which fail are backed off exponentially. Normal (non-continuous) jobs will be
allowed to run to completion to preserve their current semantics.

Scheduler behavior can configured by these configuration options in
`[replicator]` sections:

 * `max_jobs` : Number of actively running replications. Making this too high
 could cause performance issues. Making it too low could mean replications jobs
 might not have enough time to make progress before getting unscheduled again.
 This parameter can be adjusted at runtime and will take effect during next
 reschudling cycle.

 * `interval` : Scheduling interval in milliseconds. During each reschedule
 cycle scheduler might start or stop up to "max_churn" number of jobs.

 * `max_churn` : Maximum number of replications to start and stop during
 rescheduling. This parameter along with "interval" defines the rate of job
 replacement. During startup, however a much larger number of jobs could be
 started (up to max_jobs) in short period of time.

Replication jobs are added to the scheduler by the document processor or from
the `couch_replicator:replicate/2` function when called from `_replicate` HTTP
endpoint handler.

Document processor listens for updates via couch_mutlidb_changes module then
tries to add replication jobs to the scheduler. Sometimes translating a
document update to a replication job could fail, either permantly (if document
is malformed and missing some expected fields for example) or temporarily if
it is a filtered replication and filter cannot be fetched. A failed filter
fetch will be retried with an exponential backoff.

couch_replicator_clustering is in charge of monitoring cluster membership
changes. When membership changes, after a configurable quiet period, a rescan
will be initiated. Rescan will shufle replication jobs to make sure a
replication job is running on only one node.

A new set of stats were added to introspect scheduler and doc processor
internals.

The top replication supervisor structure is `rest_for_one`. This means if
a child crashes, all children to the "right" of it will be restarted (if
visualized supervisor hierarchy as an upside-down tree). Clustering,
connection pool and rate limiter are towards the "left" as they are more
fundamental, if clustering child crashes, most other components will be
restart. Doc process or and multi-db changes children are towards the "right".
If they crash, they can be safely restarted without affecting already running
replication or components like clustering or connection pool.

Jira: COUCHDB-3324
</pre>
</div>
</content>
</entry>
<entry>
<title>Add 'src/couch_replicator/' from commit 'd00b981445c03622497088eb872059ab4f48b298'</title>
<updated>2017-04-01T17:38:46+00:00</updated>
<author>
<name>Jan Lehnardt</name>
<email>jan@apache.org</email>
</author>
<published>2017-04-01T17:38:46+00:00</published>
<link rel='alternate' type='text/html' href='http://trove.baserock.org/cgit/delta/couchdb.git/commit/?id=6368e92b6dc0bc4197fa9bcac64af77a9c4887fe'/>
<id>6368e92b6dc0bc4197fa9bcac64af77a9c4887fe</id>
<content type='text'>
git-subtree-dir: src/couch_replicator
git-subtree-mainline: b758bbe49890be6069022b681aae1a581d825fb0
git-subtree-split: d00b981445c03622497088eb872059ab4f48b298
</content>
<content type='xhtml'>
<div xmlns='http://www.w3.org/1999/xhtml'>
<pre>
git-subtree-dir: src/couch_replicator
git-subtree-mainline: b758bbe49890be6069022b681aae1a581d825fb0
git-subtree-split: d00b981445c03622497088eb872059ab4f48b298
</pre>
</div>
</content>
</entry>
</feed>
