2727import org .apache .druid .java .util .common .HumanReadableBytes ;
2828import org .apache .druid .java .util .common .HumanReadableBytesRange ;
2929import org .apache .druid .segment .loading .SegmentLoaderConfig ;
30+ import org .apache .druid .utils .RuntimeInfo ;
3031
3132import javax .validation .constraints .NotNull ;
3233import java .util .Set ;
3536 */
3637public class DruidServerConfig
3738{
39+ private static final long VIRTUAL_CAPACITY_PER_GIB_OF_HEAP = HumanReadableBytes .parse ("15TiB" );
40+ private static final long ONE_GIB = HumanReadableBytes .parse ("1GiB" );
41+
3842 @ JsonProperty
3943 @ HumanReadableBytesRange (min = 0 )
4044 private HumanReadableBytes maxSize = HumanReadableBytes .ZERO ;
@@ -51,21 +55,34 @@ public class DruidServerConfig
5155 "druid.metadata.storage.connector.password" ,
5256 "password" , "key" , "token" , "pwd" );
5357
58+ private final RuntimeInfo runtimeInfo ;
5459 private SegmentLoaderConfig segmentLoaderConfig ;
5560
5661 // Guice inject added here to properly bind this dependency into its dependents such as StatusResource
5762 @ Inject
5863 @ JsonCreator
5964 public DruidServerConfig (
65+ @ JacksonInject RuntimeInfo runtimeInfo ,
6066 @ JacksonInject SegmentLoaderConfig segmentLoaderConfig
6167 )
6268 {
6369 this .segmentLoaderConfig = segmentLoaderConfig ;
70+ this .runtimeInfo = runtimeInfo ;
6471 }
6572
73+ /**
74+ * The maximum size in bytes a data node advertises itself as having available to serve data. If not set explicitly,
75+ * this value is computed. By default this value is computed using {@link SegmentLoaderConfig#getCombinedMaxSize()}
76+ * which is the total physical capacity of the segment storage locations. If the data node is using virtual storage
77+ * mode, the default is instead computed based on an assumption that ~1G of heap is "plenty" to be able to serve ~50k
78+ * segments, using ~300M segment size as the conversion to storage space translates to ~15T of segments per 1G of heap
79+ */
6680 public long getMaxSize ()
6781 {
6882 if (maxSize .equals (HumanReadableBytes .ZERO )) {
83+ if (segmentLoaderConfig .isVirtualStorage ()) {
84+ return VIRTUAL_CAPACITY_PER_GIB_OF_HEAP * (runtimeInfo .getMaxHeapSizeBytes () / ONE_GIB );
85+ }
6986 return segmentLoaderConfig .getCombinedMaxSize ();
7087 }
7188 return maxSize .getBytes ();
0 commit comments