46
46
import org .elasticsearch .cluster .routing .ShardRoutingState ;
47
47
import org .elasticsearch .cluster .routing .allocation .AllocationService ;
48
48
import org .elasticsearch .cluster .service .ClusterService ;
49
+ import org .elasticsearch .common .Nullable ;
49
50
import org .elasticsearch .common .Priority ;
50
51
import org .elasticsearch .common .Strings ;
51
52
import org .elasticsearch .common .UUIDs ;
52
53
import org .elasticsearch .common .ValidationException ;
53
54
import org .elasticsearch .common .compress .CompressedXContent ;
54
55
import org .elasticsearch .common .io .PathUtils ;
56
+ import org .elasticsearch .common .logging .DeprecationLogger ;
55
57
import org .elasticsearch .common .settings .IndexScopedSettings ;
56
58
import org .elasticsearch .common .settings .Setting ;
57
59
import org .elasticsearch .common .settings .Settings ;
68
70
import org .elasticsearch .indices .IndexCreationException ;
69
71
import org .elasticsearch .indices .IndicesService ;
70
72
import org .elasticsearch .indices .InvalidIndexNameException ;
73
+ import org .elasticsearch .indices .SystemIndexDescriptor ;
71
74
import org .elasticsearch .indices .cluster .IndicesClusterStateService .AllocatedIndices .IndexRemovalReason ;
72
75
import org .elasticsearch .threadpool .ThreadPool ;
73
76
80
83
import java .util .List ;
81
84
import java .util .Locale ;
82
85
import java .util .Map ;
86
+ import java .util .Objects ;
83
87
import java .util .Optional ;
84
88
import java .util .Set ;
85
89
import java .util .concurrent .atomic .AtomicInteger ;
98
102
*/
99
103
public class MetaDataCreateIndexService {
100
104
private static final Logger logger = LogManager .getLogger (MetaDataCreateIndexService .class );
105
+ private static final DeprecationLogger deprecationLogger = new DeprecationLogger (logger );
101
106
102
107
public static final int MAX_INDEX_NAME_BYTES = 255 ;
103
108
@@ -110,19 +115,21 @@ public class MetaDataCreateIndexService {
110
115
private final IndexScopedSettings indexScopedSettings ;
111
116
private final ActiveShardsObserver activeShardsObserver ;
112
117
private final NamedXContentRegistry xContentRegistry ;
118
+ private final Map <String , SystemIndexDescriptor > systemIndexDescriptors ;
113
119
private final boolean forbidPrivateIndexSettings ;
114
120
115
121
public MetaDataCreateIndexService (
116
- final Settings settings ,
117
- final ClusterService clusterService ,
118
- final IndicesService indicesService ,
119
- final AllocationService allocationService ,
120
- final AliasValidator aliasValidator ,
121
- final Environment env ,
122
- final IndexScopedSettings indexScopedSettings ,
123
- final ThreadPool threadPool ,
124
- final NamedXContentRegistry xContentRegistry ,
125
- final boolean forbidPrivateIndexSettings ) {
122
+ final Settings settings ,
123
+ final ClusterService clusterService ,
124
+ final IndicesService indicesService ,
125
+ final AllocationService allocationService ,
126
+ final AliasValidator aliasValidator ,
127
+ final Environment env ,
128
+ final IndexScopedSettings indexScopedSettings ,
129
+ final ThreadPool threadPool ,
130
+ final NamedXContentRegistry xContentRegistry ,
131
+ final Map <String , SystemIndexDescriptor > systemIndexDescriptors ,
132
+ final boolean forbidPrivateIndexSettings ) {
126
133
this .settings = settings ;
127
134
this .clusterService = clusterService ;
128
135
this .indicesService = indicesService ;
@@ -132,17 +139,23 @@ public MetaDataCreateIndexService(
132
139
this .indexScopedSettings = indexScopedSettings ;
133
140
this .activeShardsObserver = new ActiveShardsObserver (clusterService , threadPool );
134
141
this .xContentRegistry = xContentRegistry ;
142
+ this .systemIndexDescriptors = systemIndexDescriptors ;
135
143
this .forbidPrivateIndexSettings = forbidPrivateIndexSettings ;
136
144
}
137
145
138
146
/**
139
147
* Validate the name for an index against some static rules and a cluster state.
148
+ * Set of allowed system index names is *optional* - provide it only if you want to allow certain dot-prefixed names.
140
149
*/
141
- public static void validateIndexName (String index , ClusterState state ) {
150
+ public static void validateIndexName (String index , ClusterState state , @ Nullable final Set < String > allowedSystemIndices ) {
142
151
validateIndexOrAliasName (index , InvalidIndexNameException ::new );
143
152
if (!index .toLowerCase (Locale .ROOT ).equals (index )) {
144
153
throw new InvalidIndexNameException (index , "must be lowercase" );
145
154
}
155
+ if (index .charAt (0 ) == '.' && (Objects .isNull (allowedSystemIndices ) || allowedSystemIndices .contains (index ) == false )) {
156
+ deprecationLogger .deprecated ("index name [{}] starts with a dot '.', in the next major version, creating indices with " +
157
+ "names starting with a dot will fail as these names are reserved for system indices" , index );
158
+ }
146
159
if (state .routingTable ().hasIndex (index )) {
147
160
throw new ResourceAlreadyExistsException (state .routingTable ().index (index ).getIndex ());
148
161
}
@@ -591,7 +604,7 @@ public void onFailure(String source, Exception e) {
591
604
}
592
605
593
606
private void validate (CreateIndexClusterStateUpdateRequest request , ClusterState state ) {
594
- validateIndexName (request .index (), state );
607
+ validateIndexName (request .index (), state , systemIndexDescriptors . keySet () );
595
608
validateIndexSettings (request .index (), request .settings (), forbidPrivateIndexSettings );
596
609
}
597
610
0 commit comments