1313import org .elasticsearch .Assertions ;
1414import org .elasticsearch .action .ActionListener ;
1515import org .elasticsearch .action .StepListener ;
16+ import org .elasticsearch .cluster .node .DiscoveryNodeRole ;
1617import org .elasticsearch .common .Nullable ;
1718import org .elasticsearch .common .lease .Releasable ;
1819import org .elasticsearch .common .lease .Releasables ;
20+ import org .elasticsearch .common .logging .DeprecationCategory ;
21+ import org .elasticsearch .common .logging .DeprecationLogger ;
1922import org .elasticsearch .common .settings .Setting ;
2023import org .elasticsearch .common .settings .Settings ;
24+ import org .elasticsearch .common .settings .SettingsException ;
2125import org .elasticsearch .common .unit .ByteSizeUnit ;
2226import org .elasticsearch .common .unit .ByteSizeValue ;
2327import org .elasticsearch .common .unit .TimeValue ;
3034import org .elasticsearch .index .shard .ShardId ;
3135import org .elasticsearch .index .store .cache .CacheKey ;
3236import org .elasticsearch .index .store .cache .SparseFileTracker ;
37+ import org .elasticsearch .node .NodeRoleSettings ;
3338import org .elasticsearch .threadpool .ThreadPool ;
39+ import org .elasticsearch .xpack .core .DataTier ;
3440
3541import java .io .IOException ;
3642import java .io .UncheckedIOException ;
3743import java .util .ArrayList ;
44+ import java .util .Collections ;
45+ import java .util .HashSet ;
46+ import java .util .Iterator ;
3847import java .util .List ;
48+ import java .util .Map ;
3949import java .util .Objects ;
4050import java .util .concurrent .ConcurrentHashMap ;
4151import java .util .concurrent .ConcurrentLinkedQueue ;
4555import java .util .function .Consumer ;
4656import java .util .function .LongSupplier ;
4757import java .util .function .Predicate ;
58+ import java .util .stream .Collectors ;
4859
4960import static org .elasticsearch .xpack .searchablesnapshots .SearchableSnapshotsUtils .toIntBytes ;
5061
@@ -67,9 +78,45 @@ public class FrozenCacheService implements Releasable {
6778 Setting .Property .NodeScope
6879 );
6980
70- public static final Setting <ByteSizeValue > SNAPSHOT_CACHE_SIZE_SETTING = Setting . byteSizeSetting (
81+ public static final Setting <ByteSizeValue > SNAPSHOT_CACHE_SIZE_SETTING = new Setting <> (
7182 SHARED_CACHE_SETTINGS_PREFIX + "size" ,
72- ByteSizeValue .ZERO ,
83+ ByteSizeValue .ZERO .getStringRep (),
84+ s -> ByteSizeValue .parseBytesSizeValue (s , SHARED_CACHE_SETTINGS_PREFIX + "size" ),
85+ new Setting .Validator <ByteSizeValue >() {
86+
87+ @ Override
88+ public void validate (final ByteSizeValue value ) {
89+
90+ }
91+
92+ @ Override
93+ public void validate (final ByteSizeValue value , final Map <Setting <?>, Object > settings ) {
94+ if (value .getBytes () == -1 ) {
95+ throw new SettingsException ("setting [{}] must be non-negative" , SHARED_CACHE_SETTINGS_PREFIX + "size" );
96+ }
97+ if (value .getBytes () > 0 ) {
98+ @ SuppressWarnings ("unchecked" )
99+ final List <DiscoveryNodeRole > roles = (List <DiscoveryNodeRole >) settings .get (NodeRoleSettings .NODE_ROLES_SETTING );
100+ if (DataTier .isFrozenNode (new HashSet <>(roles )) == false ) {
101+ deprecationLogger .deprecate (
102+ DeprecationCategory .SETTINGS ,
103+ "shared_cache" ,
104+ "setting [{}] to be positive [{}] on node without the data_frozen role is deprecated, roles are [{}]" ,
105+ SHARED_CACHE_SETTINGS_PREFIX + "size" ,
106+ value .getStringRep (),
107+ roles .stream ().map (DiscoveryNodeRole ::roleName ).collect (Collectors .joining ("," ))
108+ );
109+ }
110+ }
111+ }
112+
113+ @ Override
114+ public Iterator <Setting <?>> settings () {
115+ final List <Setting <?>> settings = Collections .singletonList (NodeRoleSettings .NODE_ROLES_SETTING );
116+ return settings .iterator ();
117+ }
118+
119+ },
73120 Setting .Property .NodeScope
74121 );
75122
@@ -105,6 +152,7 @@ public class FrozenCacheService implements Releasable {
105152 );
106153
107154 private static final Logger logger = LogManager .getLogger (FrozenCacheService .class );
155+ private static final DeprecationLogger deprecationLogger = DeprecationLogger .getLogger (FrozenCacheService .class );
108156
109157 private final ConcurrentHashMap <RegionKey , Entry <CacheFileRegion >> keyMapping ;
110158
0 commit comments