blob: 5d630f5463e0ee2a974f7de9acfb87ad0a80701d [file] [log] [blame]
"use strict";(self.webpackChunk=self.webpackChunk||[]).push([[3535],{3905:(e,t,o)=>{o.d(t,{Zo:()=>p,kt:()=>h});var n=o(7294);function a(e,t,o){return t in e?Object.defineProperty(e,t,{value:o,enumerable:!0,configurable:!0,writable:!0}):e[t]=o,e}function i(e,t){var o=Object.keys(e);if(Object.getOwnPropertySymbols){var n=Object.getOwnPropertySymbols(e);t&&(n=n.filter((function(t){return Object.getOwnPropertyDescriptor(e,t).enumerable}))),o.push.apply(o,n)}return o}function r(e){for(var t=1;t<arguments.length;t++){var o=null!=arguments[t]?arguments[t]:{};t%2?i(Object(o),!0).forEach((function(t){a(e,t,o[t])})):Object.getOwnPropertyDescriptors?Object.defineProperties(e,Object.getOwnPropertyDescriptors(o)):i(Object(o)).forEach((function(t){Object.defineProperty(e,t,Object.getOwnPropertyDescriptor(o,t))}))}return e}function s(e,t){if(null==e)return{};var o,n,a=function(e,t){if(null==e)return{};var o,n,a={},i=Object.keys(e);for(n=0;n<i.length;n++)o=i[n],t.indexOf(o)>=0||(a[o]=e[o]);return a}(e,t);if(Object.getOwnPropertySymbols){var i=Object.getOwnPropertySymbols(e);for(n=0;n<i.length;n++)o=i[n],t.indexOf(o)>=0||Object.prototype.propertyIsEnumerable.call(e,o)&&(a[o]=e[o])}return a}var l=n.createContext({}),c=function(e){var t=n.useContext(l),o=t;return e&&(o="function"==typeof e?e(t):r(r({},t),e)),o},p=function(e){var t=c(e.components);return n.createElement(l.Provider,{value:t},e.children)},d="mdxType",m={inlineCode:"code",wrapper:function(e){var t=e.children;return n.createElement(n.Fragment,{},t)}},u=n.forwardRef((function(e,t){var o=e.components,a=e.mdxType,i=e.originalType,l=e.parentName,p=s(e,["components","mdxType","originalType","parentName"]),d=c(o),u=a,h=d["".concat(l,".").concat(u)]||d[u]||m[u]||i;return o?n.createElement(h,r(r({ref:t},p),{},{components:o})):n.createElement(h,r({ref:t},p))}));function h(e,t){var o=arguments,a=t&&t.mdxType;if("string"==typeof e||a){var i=o.length,r=new Array(i);r[0]=u;var s={};for(var l in t)hasOwnProperty.call(t,l)&&(s[l]=t[l]);s.originalType=e,s[d]="string"==typeof e?e:a,r[1]=s;for(var c=2;c<i;c++)r[c]=o[c];return n.createElement.apply(null,r)}return n.createElement.apply(null,o)}u.displayName="MDXCreateElement"},1502:(e,t,o)=>{o.r(t),o.d(t,{assets:()=>p,contentTitle:()=>l,default:()=>h,frontMatter:()=>s,metadata:()=>c,toc:()=>d});var n=o(7462),a=o(3366),i=(o(7294),o(3905)),r=["components"],s={id:"coordinator",title:"Coordinator Process"},l=void 0,c={unversionedId:"design/coordinator",id:"design/coordinator",title:"Coordinator Process",description:"\x3c!--",source:"@site/docs/latest/design/coordinator.md",sourceDirName:"design",slug:"/design/coordinator",permalink:"/docs/latest/design/coordinator",draft:!1,tags:[],version:"current",frontMatter:{id:"coordinator",title:"Coordinator Process"}},p={},d=[{value:"Configuration",id:"configuration",level:3},{value:"HTTP endpoints",id:"http-endpoints",level:3},{value:"Overview",id:"overview",level:3},{value:"Running",id:"running",level:3},{value:"Rules",id:"rules",level:3},{value:"Cleaning up segments",id:"cleaning-up-segments",level:3},{value:"Segment availability",id:"segment-availability",level:3},{value:"Balancing segment load",id:"balancing-segment-load",level:3},{value:"Automatic compaction",id:"automatic-compaction",level:3},{value:"Segment search policy in automatic compaction",id:"segment-search-policy-in-automatic-compaction",level:3},{value:"FAQ",id:"faq",level:3}],m={toc:d},u="wrapper";function h(e){var t=e.components,o=(0,a.Z)(e,r);return(0,i.kt)(u,(0,n.Z)({},m,o,{components:t,mdxType:"MDXLayout"}),(0,i.kt)("h3",{id:"configuration"},"Configuration"),(0,i.kt)("p",null,"For Apache Druid Coordinator Process Configuration, see ",(0,i.kt)("a",{parentName:"p",href:"/docs/latest/configuration/#coordinator"},"Coordinator Configuration"),"."),(0,i.kt)("p",null,"For basic tuning guidance for the Coordinator process, see ",(0,i.kt)("a",{parentName:"p",href:"/docs/latest/operations/basic-cluster-tuning#coordinator"},"Basic cluster tuning"),"."),(0,i.kt)("h3",{id:"http-endpoints"},"HTTP endpoints"),(0,i.kt)("p",null,"For a list of API endpoints supported by the Coordinator, see ",(0,i.kt)("a",{parentName:"p",href:"/docs/latest/operations/api-reference#coordinator"},"Coordinator API"),"."),(0,i.kt)("h3",{id:"overview"},"Overview"),(0,i.kt)("p",null,'The Druid Coordinator process is primarily responsible for segment management and distribution. More specifically, the\nDruid Coordinator process communicates to Historical processes to load or drop segments based on configurations. The\nDruid Coordinator is responsible for loading new segments, dropping outdated segments, ensuring that segments are\n"replicated" (that is, loaded on multiple different Historical nodes) proper (configured) number of times, and moving\n("balancing") segments between Historical nodes to keep the latter evenly loaded.'),(0,i.kt)("p",null,'The Druid Coordinator runs its duties periodically and the time between each run is a configurable parameter. On each\nrun, the Coordinator assesses the current state of the cluster before deciding on the appropriate actions to take.\nSimilar to the Broker and Historical processes, the Druid Coordinator maintains a connection to a Zookeeper cluster for\ncurrent cluster information. The Coordinator also maintains a connection to a database containing information about\n"used" segments (that is, the segments that ',(0,i.kt)("em",{parentName:"p"},"should")," be loaded in the cluster) and the loading rules."),(0,i.kt)("p",null,"Before any unassigned segments are serviced by Historical processes, the Historical processes for each tier are first\nsorted in terms of capacity, with least capacity servers having the highest priority. Unassigned segments are always\nassigned to the processes with least capacity to maintain a level of balance between processes. The Coordinator does not\ndirectly communicate with a historical process when assigning it a new segment; instead the Coordinator creates some\ntemporary information about the new segment under load queue path of the historical process. Once this request is seen,\nthe historical process will load the segment and begin servicing it."),(0,i.kt)("h3",{id:"running"},"Running"),(0,i.kt)("pre",null,(0,i.kt)("code",{parentName:"pre"},"org.apache.druid.cli.Main server coordinator\n")),(0,i.kt)("h3",{id:"rules"},"Rules"),(0,i.kt)("p",null,"Segments can be automatically loaded and dropped from the cluster based on a set of rules. For more information on rules, see ",(0,i.kt)("a",{parentName:"p",href:"/docs/latest/operations/rule-configuration"},"Rule Configuration"),"."),(0,i.kt)("h3",{id:"cleaning-up-segments"},"Cleaning up segments"),(0,i.kt)("p",null,"On each run, the Druid Coordinator compares the set of used segments in the database with the segments served by some\nHistorical nodes in the cluster. Coordinator sends requests to Historical nodes to unload unused segments or segments\nthat are removed from the database."),(0,i.kt)("p",null,"Segments that are overshadowed (their versions are too old and their data has been replaced by newer segments) are\nmarked as unused. During the next Coordinator's run, they will be unloaded from Historical nodes in the cluster."),(0,i.kt)("h3",{id:"segment-availability"},"Segment availability"),(0,i.kt)("p",null,"If a Historical process restarts or becomes unavailable for any reason, the Druid Coordinator will notice a process has gone missing and treat all segments served by that process as being dropped. Given a sufficient period of time, the segments may be reassigned to other Historical processes in the cluster. However, each segment that is dropped is not immediately forgotten. Instead, there is a transitional data structure that stores all dropped segments with an associated lifetime. The lifetime represents a period of time in which the Coordinator will not reassign a dropped segment. Hence, if a historical process becomes unavailable and available again within a short period of time, the historical process will start up and serve segments from its cache without any those segments being reassigned across the cluster."),(0,i.kt)("h3",{id:"balancing-segment-load"},"Balancing segment load"),(0,i.kt)("p",null,"To ensure an even distribution of segments across Historical processes in the cluster, the Coordinator process will find the total size of all segments being served by every Historical process each time the Coordinator runs. For every Historical process tier in the cluster, the Coordinator process will determine the Historical process with the highest utilization and the Historical process with the lowest utilization. The percent difference in utilization between the two processes is computed, and if the result exceeds a certain threshold, a number of segments will be moved from the highest utilized process to the lowest utilized process. There is a configurable limit on the number of segments that can be moved from one process to another each time the Coordinator runs. Segments to be moved are selected at random and only moved if the resulting utilization calculation indicates the percentage difference between the highest and lowest servers has decreased."),(0,i.kt)("h3",{id:"automatic-compaction"},"Automatic compaction"),(0,i.kt)("p",null,"The Druid Coordinator manages the ",(0,i.kt)("a",{parentName:"p",href:"/docs/latest/data-management/automatic-compaction"},"automatic compaction system"),".\nEach run, the Coordinator compacts segments by merging small segments or splitting a large one. This is useful when the size of your segments is not optimized which may degrade query performance.\nSee ",(0,i.kt)("a",{parentName:"p",href:"/docs/latest/operations/segment-optimization"},"Segment size optimization")," for details."),(0,i.kt)("p",null,"The Coordinator first finds the segments to compact based on the ",(0,i.kt)("a",{parentName:"p",href:"#segment-search-policy-in-automatic-compaction"},"segment search policy"),".\nOnce some segments are found, it issues a ",(0,i.kt)("a",{parentName:"p",href:"/docs/latest/ingestion/tasks#compact"},"compaction task")," to compact those segments.\nThe maximum number of running compaction tasks is ",(0,i.kt)("inlineCode",{parentName:"p"},"min(sum of worker capacity * slotRatio, maxSlots)"),".\nNote that even if ",(0,i.kt)("inlineCode",{parentName:"p"},"min(sum of worker capacity * slotRatio, maxSlots) = 0"),", at least one compaction task is always submitted\nif the compaction is enabled for a dataSource.\nSee ",(0,i.kt)("a",{parentName:"p",href:"/docs/latest/operations/api-reference#automatic-compaction-configuration"},"Automatic compaction configuration API")," and ",(0,i.kt)("a",{parentName:"p",href:"/docs/latest/configuration/#automatic-compaction-dynamic-configuration"},"Automatic compaction configuration")," to enable and configure automatic compaction."),(0,i.kt)("p",null,"Compaction tasks might fail due to the following reasons:"),(0,i.kt)("ul",null,(0,i.kt)("li",{parentName:"ul"},"If the input segments of a compaction task are removed or overshadowed before it starts, that compaction task fails immediately."),(0,i.kt)("li",{parentName:"ul"},"If a task of a higher priority acquires a ",(0,i.kt)("a",{parentName:"li",href:"/docs/latest/ingestion/tasks#locking"},"time chunk lock")," for an interval overlapping with the interval of a compaction task, the compaction task fails.")),(0,i.kt)("p",null,"Once a compaction task fails, the Coordinator simply checks the segments in the interval of the failed task again, and issues another compaction task in the next run."),(0,i.kt)("p",null,"Note that Compacting Segments Coordinator Duty is automatically enabled and run as part of the Indexing Service Duties group. However, Compacting Segments Coordinator Duty can be configured to run in isolation as a separate Coordinator duty group. This allows changing the period of Compacting Segments Coordinator Duty without impacting the period of other Indexing Service Duties. This can be done by setting the following properties. For more details, see ",(0,i.kt)("a",{parentName:"p",href:"/docs/latest/development/modules#adding-your-own-custom-pluggable-coordinator-duty"},"custom pluggable Coordinator Duty"),"."),(0,i.kt)("pre",null,(0,i.kt)("code",{parentName:"pre"},'druid.coordinator.dutyGroups=[<SOME_GROUP_NAME>]\ndruid.coordinator.<SOME_GROUP_NAME>.duties=["compactSegments"]\ndruid.coordinator.<SOME_GROUP_NAME>.period=<PERIOD_TO_RUN_COMPACTING_SEGMENTS_DUTY>\n')),(0,i.kt)("h3",{id:"segment-search-policy-in-automatic-compaction"},"Segment search policy in automatic compaction"),(0,i.kt)("p",null,"At every Coordinator run, this policy looks up time chunks from newest to oldest and checks whether the segments in those time chunks\nneed compaction.\nA set of segments needs compaction if all conditions below are satisfied:"),(0,i.kt)("p",null,"1) Total size of segments in the time chunk is smaller than or equal to the configured ",(0,i.kt)("inlineCode",{parentName:"p"},"inputSegmentSizeBytes"),".\n2) Segments have never been compacted yet or compaction spec has been updated since the last compaction: ",(0,i.kt)("inlineCode",{parentName:"p"},"maxTotalRows")," or ",(0,i.kt)("inlineCode",{parentName:"p"},"indexSpec"),"."),(0,i.kt)("p",null,"Here are some details with an example. Suppose we have two dataSources (",(0,i.kt)("inlineCode",{parentName:"p"},"foo"),", ",(0,i.kt)("inlineCode",{parentName:"p"},"bar"),") as seen below:"),(0,i.kt)("ul",null,(0,i.kt)("li",{parentName:"ul"},(0,i.kt)("inlineCode",{parentName:"li"},"foo"),(0,i.kt)("ul",{parentName:"li"},(0,i.kt)("li",{parentName:"ul"},(0,i.kt)("inlineCode",{parentName:"li"},"foo_2017-11-01T00:00:00.000Z_2017-12-01T00:00:00.000Z_VERSION")),(0,i.kt)("li",{parentName:"ul"},(0,i.kt)("inlineCode",{parentName:"li"},"foo_2017-11-01T00:00:00.000Z_2017-12-01T00:00:00.000Z_VERSION_1")),(0,i.kt)("li",{parentName:"ul"},(0,i.kt)("inlineCode",{parentName:"li"},"foo_2017-09-01T00:00:00.000Z_2017-10-01T00:00:00.000Z_VERSION")))),(0,i.kt)("li",{parentName:"ul"},(0,i.kt)("inlineCode",{parentName:"li"},"bar"),(0,i.kt)("ul",{parentName:"li"},(0,i.kt)("li",{parentName:"ul"},(0,i.kt)("inlineCode",{parentName:"li"},"bar_2017-10-01T00:00:00.000Z_2017-11-01T00:00:00.000Z_VERSION")),(0,i.kt)("li",{parentName:"ul"},(0,i.kt)("inlineCode",{parentName:"li"},"bar_2017-10-01T00:00:00.000Z_2017-11-01T00:00:00.000Z_VERSION_1"))))),(0,i.kt)("p",null,"Assuming that each segment is 10 MB and haven't been compacted yet, this policy first returns two segments of\n",(0,i.kt)("inlineCode",{parentName:"p"},"foo_2017-11-01T00:00:00.000Z_2017-12-01T00:00:00.000Z_VERSION")," and ",(0,i.kt)("inlineCode",{parentName:"p"},"foo_2017-11-01T00:00:00.000Z_2017-12-01T00:00:00.000Z_VERSION_1")," to compact together because\n",(0,i.kt)("inlineCode",{parentName:"p"},"2017-11-01T00:00:00.000Z/2017-12-01T00:00:00.000Z")," is the most recent time chunk."),(0,i.kt)("p",null,"If the Coordinator has enough task slots for compaction, this policy will continue searching for the next segments and return\n",(0,i.kt)("inlineCode",{parentName:"p"},"bar_2017-10-01T00:00:00.000Z_2017-11-01T00:00:00.000Z_VERSION")," and ",(0,i.kt)("inlineCode",{parentName:"p"},"bar_2017-10-01T00:00:00.000Z_2017-11-01T00:00:00.000Z_VERSION_1"),".\nFinally, ",(0,i.kt)("inlineCode",{parentName:"p"},"foo_2017-09-01T00:00:00.000Z_2017-10-01T00:00:00.000Z_VERSION")," will be picked up even though there is only one segment in the time chunk of ",(0,i.kt)("inlineCode",{parentName:"p"},"2017-09-01T00:00:00.000Z/2017-10-01T00:00:00.000Z"),"."),(0,i.kt)("p",null,"The search start point can be changed by setting ",(0,i.kt)("inlineCode",{parentName:"p"},"skipOffsetFromLatest"),".\nIf this is set, this policy will ignore the segments falling into the time chunk of (the end time of the most recent segment - ",(0,i.kt)("inlineCode",{parentName:"p"},"skipOffsetFromLatest"),").\nThis is to avoid conflicts between compaction tasks and realtime tasks.\nNote that realtime tasks have a higher priority than compaction tasks by default. Realtime tasks will revoke the locks of compaction tasks if their intervals overlap, resulting in the termination of the compaction task.\nFor more information, see ",(0,i.kt)("a",{parentName:"p",href:"/docs/latest/data-management/automatic-compaction#avoid-conflicts-with-ingestion"},"Avoid conflicts with ingestion"),"."),(0,i.kt)("blockquote",null,(0,i.kt)("p",{parentName:"blockquote"},"This policy currently cannot handle the situation when there are a lot of small segments which have the same interval,\nand their total size exceeds ",(0,i.kt)("a",{parentName:"p",href:"/docs/latest/configuration/#automatic-compaction-dynamic-configuration"},(0,i.kt)("inlineCode",{parentName:"a"},"inputSegmentSizeBytes")),".\nIf it finds such segments, it simply skips them.")),(0,i.kt)("h3",{id:"faq"},"FAQ"),(0,i.kt)("ol",null,(0,i.kt)("li",{parentName:"ol"},(0,i.kt)("p",{parentName:"li"},(0,i.kt)("strong",{parentName:"p"},"Do clients ever contact the Coordinator process?")),(0,i.kt)("p",{parentName:"li"},"The Coordinator is not involved in a query."),(0,i.kt)("p",{parentName:"li"},"Historical processes never directly contact the Coordinator process. The Druid Coordinator tells the Historical processes to load/drop data via Zookeeper, but the Historical processes are completely unaware of the Coordinator."),(0,i.kt)("p",{parentName:"li"},"Brokers also never contact the Coordinator. Brokers base their understanding of the data topology on metadata exposed by the Historical processes via ZK and are completely unaware of the Coordinator.")),(0,i.kt)("li",{parentName:"ol"},(0,i.kt)("p",{parentName:"li"},(0,i.kt)("strong",{parentName:"p"},"Does it matter if the Coordinator process starts up before or after other processes?")),(0,i.kt)("p",{parentName:"li"},"No. If the Druid Coordinator is not started up, no new segments will be loaded in the cluster and outdated segments will not be dropped. However, the Coordinator process can be started up at any time, and after a configurable delay, will start running Coordinator tasks."),(0,i.kt)("p",{parentName:"li"},"This also means that if you have a working cluster and all of your Coordinators die, the cluster will continue to function, it just won\u2019t experience any changes to its data topology."))))}h.isMDXComponent=!0}}]);