/** * Serializes information about a single repository * * @param repository repository metadata * @param builder XContent builder * @param params serialization parameters */ public static void toXContent(RepositoryMetaData repository, XContentBuilder builder, ToXContent.Params params) throws IOException { builder.startObject(repository.name()); builder.field("type", repository.type()); builder.startObject("settings"); repository.settings().toXContent(builder, params); builder.endObject(); builder.endObject(); } }
@Override protected BlobStore createBlobStore() throws Exception { final String location = REPOSITORIES_LOCATION_SETTING.get(metadata.settings()); final Path locationFile = environment.resolveRepoFile(location); return new FsBlobStore(environment.settings(), locationFile); }
/** * Constructs new BlobStoreRepository * * @param metadata The metadata for this repository including name and settings * @param settings Settings for the node this repository object is created on */ protected BlobStoreRepository(RepositoryMetaData metadata, Settings settings, NamedXContentRegistry namedXContentRegistry) { super(settings); this.settings = settings; this.metadata = metadata; this.namedXContentRegistry = namedXContentRegistry; snapshotRateLimiter = getRateLimiter(metadata.settings(), "max_snapshot_bytes_per_sec", new ByteSizeValue(40, ByteSizeUnit.MB)); restoreRateLimiter = getRateLimiter(metadata.settings(), "max_restore_bytes_per_sec", new ByteSizeValue(40, ByteSizeUnit.MB)); readOnly = metadata.settings().getAsBoolean("readonly", false); indexShardSnapshotFormat = new ChecksumBlobStoreFormat<>(SNAPSHOT_CODEC, SNAPSHOT_NAME_FORMAT, BlobStoreIndexShardSnapshot::fromXContent, namedXContentRegistry, isCompress()); indexShardSnapshotsFormat = new ChecksumBlobStoreFormat<>(SNAPSHOT_INDEX_CODEC, SNAPSHOT_INDEX_NAME_FORMAT, BlobStoreIndexShardSnapshots::fromXContent, namedXContentRegistry, isCompress()); ByteSizeValue chunkSize = chunkSize(); if (chunkSize != null && chunkSize.getBytes() <= 0) { throw new IllegalArgumentException("the chunk size cannot be negative: [" + chunkSize + "]"); } }
super(metadata, environment.settings(), namedXContentRegistry); this.environment = environment; String location = REPOSITORIES_LOCATION_SETTING.get(metadata.settings()); if (location.isEmpty()) { logger.warn("the repository location is missing, it should point to a shared file system location" if (CHUNK_SIZE_SETTING.exists(metadata.settings())) { this.chunkSize = CHUNK_SIZE_SETTING.get(metadata.settings()); } else { this.chunkSize = REPOSITORIES_CHUNK_SIZE_SETTING.get(environment.settings()); this.compress = COMPRESS_SETTING.exists(metadata.settings()) ? COMPRESS_SETTING.get(metadata.settings()) : REPOSITORIES_COMPRESS_SETTING.get(environment.settings()); this.basePath = BlobPath.cleanPath();
/** * Serializes information about a single repository * * @param repository repository metadata * @param builder XContent builder * @param params serialization parameters */ public static void toXContent(RepositoryMetaData repository, XContentBuilder builder, ToXContent.Params params) throws IOException { builder.startObject(repository.name()); builder.field("type", repository.type()); builder.startObject("settings"); repository.settings().toXContent(builder, params); builder.endObject(); builder.endObject(); } }
/** * Serializes information about a single repository * * @param repository repository metadata * @param builder XContent builder * @param params serialization parameters */ public static void toXContent(RepositoryMetaData repository, XContentBuilder builder, ToXContent.Params params) throws IOException { builder.startObject(repository.name()); builder.field("type", repository.type()); builder.startObject("settings"); repository.settings().toXContent(builder, params); builder.endObject(); builder.endObject(); } }
/** * Serializes information about a single repository * * @param repository repository metadata * @param builder XContent builder * @param params serialization parameters */ public static void toXContent(RepositoryMetaData repository, XContentBuilder builder, ToXContent.Params params) throws IOException { builder.startObject(repository.name()); builder.field("type", repository.type()); builder.startObject("settings"); repository.settings().toXContent(builder, params); builder.endObject(); builder.endObject(); } }
/** * Serializes information about a single repository * * @param repository repository metadata * @param builder XContent builder * @param params serialization parameters */ public static void toXContent(RepositoryMetaData repository, XContentBuilder builder, ToXContent.Params params) throws IOException { builder.startObject(repository.name(), XContentBuilder.FieldCaseConversion.NONE); builder.field("type", repository.type()); builder.startObject("settings"); repository.settings().toXContent(builder, params); builder.endObject(); builder.endObject(); } }
@Override protected BlobStore createBlobStore() throws Exception { final String location = REPOSITORIES_LOCATION_SETTING.get(metadata.settings()); final Path locationFile = environment.resolveRepoFile(location); return new FsBlobStore(settings, locationFile); }
@Override protected BlobStore createBlobStore() throws Exception { final String location = REPOSITORIES_LOCATION_SETTING.get(metadata.settings()); final Path locationFile = environment.resolveRepoFile(location); return new FsBlobStore(settings, locationFile); }
/** * Creates a new repository and adds it to the list of registered repositories. * <p> * If a repository with the same name but different types or settings already exists, it will be closed and * replaced with the new repository. If a repository with the same name exists but it has the same type and settings * the new repository is ignored. * * @param repositoryMetaData new repository metadata * @return {@code true} if new repository was added or {@code false} if it was ignored */ private boolean registerRepository(RepositoryMetaData repositoryMetaData) throws IOException { Repository previous = repositories.get(repositoryMetaData.name()); if (previous != null) { RepositoryMetaData previousMetadata = previous.getMetadata(); if (!previousMetadata.type().equals(repositoryMetaData.type()) && previousMetadata.settings().equals(repositoryMetaData.settings())) { // Previous version is the same as this one - ignore it return false; } } Repository newRepo = createRepository(repositoryMetaData); if (previous != null) { closeRepository(previous); } Map<String, Repository> newRepositories = new HashMap<>(repositories); newRepositories.put(repositoryMetaData.name(), newRepo); repositories = newRepositories; return true; }
/** * Constructs new BlobStoreRepository * * @param metadata The metadata for this repository including name and settings * @param globalSettings Settings for the node this repository object is created on */ protected BlobStoreRepository(RepositoryMetaData metadata, Settings globalSettings, NamedXContentRegistry namedXContentRegistry) { super(globalSettings); this.metadata = metadata; this.namedXContentRegistry = namedXContentRegistry; snapshotRateLimiter = getRateLimiter(metadata.settings(), "max_snapshot_bytes_per_sec", new ByteSizeValue(40, ByteSizeUnit.MB)); restoreRateLimiter = getRateLimiter(metadata.settings(), "max_restore_bytes_per_sec", new ByteSizeValue(40, ByteSizeUnit.MB)); readOnly = metadata.settings().getAsBoolean("readonly", false); indexShardSnapshotFormat = new ChecksumBlobStoreFormat<>(SNAPSHOT_CODEC, SNAPSHOT_NAME_FORMAT, BlobStoreIndexShardSnapshot::fromXContent, namedXContentRegistry, isCompress()); indexShardSnapshotLegacyFormat = new LegacyBlobStoreFormat<>(LEGACY_SNAPSHOT_NAME_FORMAT, BlobStoreIndexShardSnapshot::fromXContent, namedXContentRegistry); indexShardSnapshotsFormat = new ChecksumBlobStoreFormat<>(SNAPSHOT_INDEX_CODEC, SNAPSHOT_INDEX_NAME_FORMAT, BlobStoreIndexShardSnapshots::fromXContent, namedXContentRegistry, isCompress()); }
/** * Constructs new BlobStoreRepository * * @param metadata The metadata for this repository including name and settings * @param globalSettings Settings for the node this repository object is created on */ protected BlobStoreRepository(RepositoryMetaData metadata, Settings globalSettings, NamedXContentRegistry namedXContentRegistry) { super(globalSettings); this.metadata = metadata; this.namedXContentRegistry = namedXContentRegistry; snapshotRateLimiter = getRateLimiter(metadata.settings(), "max_snapshot_bytes_per_sec", new ByteSizeValue(40, ByteSizeUnit.MB)); restoreRateLimiter = getRateLimiter(metadata.settings(), "max_restore_bytes_per_sec", new ByteSizeValue(40, ByteSizeUnit.MB)); readOnly = metadata.settings().getAsBoolean("readonly", false); indexShardSnapshotFormat = new ChecksumBlobStoreFormat<>(SNAPSHOT_CODEC, SNAPSHOT_NAME_FORMAT, BlobStoreIndexShardSnapshot::fromXContent, namedXContentRegistry, isCompress()); indexShardSnapshotsFormat = new ChecksumBlobStoreFormat<>(SNAPSHOT_INDEX_CODEC, SNAPSHOT_INDEX_NAME_FORMAT, BlobStoreIndexShardSnapshots::fromXContent, namedXContentRegistry, isCompress()); ByteSizeValue chunkSize = chunkSize(); if (chunkSize != null && chunkSize.getBytes() <= 0) { throw new IllegalArgumentException("the chunk size cannot be negative: [" + chunkSize + "]"); } }
/** * Constructs new BlobStoreRepository * * @param metadata The metadata for this repository including name and settings * @param globalSettings Settings for the node this repository object is created on */ protected BlobStoreRepository(RepositoryMetaData metadata, Settings globalSettings, NamedXContentRegistry namedXContentRegistry) { super(globalSettings); this.metadata = metadata; this.namedXContentRegistry = namedXContentRegistry; snapshotRateLimiter = getRateLimiter(metadata.settings(), "max_snapshot_bytes_per_sec", new ByteSizeValue(40, ByteSizeUnit.MB)); restoreRateLimiter = getRateLimiter(metadata.settings(), "max_restore_bytes_per_sec", new ByteSizeValue(40, ByteSizeUnit.MB)); readOnly = metadata.settings().getAsBoolean("readonly", false); indexShardSnapshotFormat = new ChecksumBlobStoreFormat<>(SNAPSHOT_CODEC, SNAPSHOT_NAME_FORMAT, BlobStoreIndexShardSnapshot::fromXContent, namedXContentRegistry, isCompress()); indexShardSnapshotsFormat = new ChecksumBlobStoreFormat<>(SNAPSHOT_INDEX_CODEC, SNAPSHOT_INDEX_NAME_FORMAT, BlobStoreIndexShardSnapshots::fromXContent, namedXContentRegistry, isCompress()); ByteSizeValue chunkSize = chunkSize(); if (chunkSize != null && chunkSize.getBytes() <= 0) { throw new IllegalArgumentException("the chunk size cannot be negative: [" + chunkSize + "]"); } }
/** * Constructs a read-only URL-based repository */ public URLRepository(RepositoryMetaData metadata, Environment environment, NamedXContentRegistry namedXContentRegistry) throws IOException { super(metadata, environment.settings(), namedXContentRegistry); if (URL_SETTING.exists(metadata.settings()) == false && REPOSITORIES_URL_SETTING.exists(settings) == false) { throw new RepositoryException(metadata.name(), "missing url"); } supportedProtocols = SUPPORTED_PROTOCOLS_SETTING.get(settings); urlWhiteList = ALLOWED_URLS_SETTING.get(settings).toArray(new URIPattern[]{}); this.environment = environment; URL url = URL_SETTING.exists(metadata.settings()) ? URL_SETTING.get(metadata.settings()) : REPOSITORIES_URL_SETTING.get(settings); URL normalizedURL = checkURL(url); blobStore = new URLBlobStore(settings, normalizedURL); basePath = BlobPath.cleanPath(); }
@Override public void writeTo(StreamOutput out) throws IOException { super.writeTo(out); out.writeVInt(repositories.size()); for (RepositoryMetaData repository : repositories) { out.writeString(repository.name()); out.writeString(repository.type()); Settings.writeSettingsToStream(repository.settings(), out); } }
@Override public void writeTo(StreamOutput out) throws IOException { super.writeTo(out); out.writeVInt(repositories.size()); for (RepositoryMetaData repository : repositories) { out.writeString(repository.name()); out.writeString(repository.type()); Settings.writeSettingsToStream(repository.settings(), out); } }
/** * Creates a new repository and adds it to the list of registered repositories. * <p> * If a repository with the same name but different types or settings already exists, it will be closed and * replaced with the new repository. If a repository with the same name exists but it has the same type and settings * the new repository is ignored. * * @param repositoryMetaData new repository metadata * @return {@code true} if new repository was added or {@code false} if it was ignored */ private boolean registerRepository(RepositoryMetaData repositoryMetaData) throws IOException { RepositoryHolder previous = repositories.get(repositoryMetaData.name()); if (previous != null) { if (!previous.type.equals(repositoryMetaData.type()) && previous.settings.equals(repositoryMetaData.settings())) { // Previous version is the same as this one - ignore it return false; } } RepositoryHolder holder = createRepositoryHolder(repositoryMetaData); if (previous != null) { // Closing previous version closeRepository(repositoryMetaData.name(), previous); } Map<String, RepositoryHolder> newRepositories = newHashMap(repositories); newRepositories.put(repositoryMetaData.name(), holder); repositories = ImmutableMap.copyOf(newRepositories); return true; }
/** * Creates repository holder */ private RepositoryHolder createRepositoryHolder(RepositoryMetaData repositoryMetaData) { logger.debug("creating repository [{}][{}]", repositoryMetaData.type(), repositoryMetaData.name()); Injector repositoryInjector = null; try { ModulesBuilder modules = new ModulesBuilder(); RepositoryName name = new RepositoryName(repositoryMetaData.type(), repositoryMetaData.name()); modules.add(new RepositoryNameModule(name)); modules.add(new RepositoryModule(name, repositoryMetaData.settings(), this.settings, typesRegistry)); repositoryInjector = modules.createChildInjector(injector); Repository repository = repositoryInjector.getInstance(Repository.class); IndexShardRepository indexShardRepository = repositoryInjector.getInstance(IndexShardRepository.class); repository.start(); return new RepositoryHolder(repositoryMetaData.type(), repositoryMetaData.settings(), repositoryInjector, repository, indexShardRepository); } catch (Throwable t) { logger.warn("failed to create repository [{}][{}]", t, repositoryMetaData.type(), repositoryMetaData.name()); throw new RepositoryException(repositoryMetaData.name(), "failed to create repository", t); } }