Skip to content

Commit

Permalink
MODSOURCE-722: relation "marc_records_tracking" does not exist
Browse files Browse the repository at this point in the history
The Poppy version of MarcIndexersVersionDeletionVerticle fails when trying to delete for tenants that are still on Orchid.

```
2023-11-21 12:14:16.453 [vert.x-worker-thread-6] [] [] [] [] ERROR RecordDaoImpl        Something happened while deleting old marc_indexers versions tenantId=ubilm
io.vertx.pgclient.PgException: ERROR: relation "marc_records_tracking" does not exist (42P01)
```

The failure prevents running the deleteMarcIndexersOldVersions of the Poppy tenants.

(cherry picked from commit 481d253)
  • Loading branch information
julianladisch authored and RuslanLavrov committed Nov 24, 2023
1 parent 8d741f8 commit 8b034e1
Show file tree
Hide file tree
Showing 4 changed files with 21 additions and 18 deletions.
3 changes: 3 additions & 0 deletions NEWS.md
Original file line number Diff line number Diff line change
@@ -1,3 +1,6 @@
## 2023-xx-xx v5.7.4
* [MODSOURCE-722](https://issues.folio.org/browse/MODSOURCE-722) deleteMarcIndexersOldVersions: relation "marc_records_tracking" does not exist

## 2023-11-09 v5.7.3
* [MODSOURCE-709](https://issues.folio.org/browse/MODSOURCE-709) MARC authority record is not created when use Job profile with match profile by absent subfield/field
* [MODSOURCE-715](https://issues.folio.org/browse/MODSOURCE-715) Change API calls to central tenant for shared BIB
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -9,9 +9,9 @@
*/
public interface TenantDataProvider {
/**
* Gets all module tenants.
* Gets all module tenants where the given database table exists.
*
* @return tenant ids
*/
Future<List<String>> getModuleTenants();
Future<List<String>> getModuleTenants(String table);
}
Original file line number Diff line number Diff line change
@@ -1,10 +1,10 @@
package org.folio.services;

import io.vertx.core.Future;
import io.vertx.core.Promise;
import io.vertx.core.Vertx;
import io.vertx.sqlclient.Row;
import io.vertx.sqlclient.RowSet;
import io.vertx.sqlclient.Tuple;

import org.folio.rest.persist.PostgresClient;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;
Expand All @@ -15,6 +15,7 @@

@Service
public class TenantDataProviderImpl implements TenantDataProvider {
private static final String SUFFIX = "_mod_source_record_storage";
private Vertx vertx;

@Autowired
Expand All @@ -23,22 +24,21 @@ public TenantDataProviderImpl(Vertx vertx) {
}

@Override
public Future<List<String>> getModuleTenants() {
public Future<List<String>> getModuleTenants(String table) {
PostgresClient pgClient = PostgresClient.getInstance(vertx);
Promise<RowSet<Row>> promise = Promise.promise();
String tenantQuery = "select nspname from pg_catalog.pg_namespace where nspname LIKE '%_mod_source_record_storage';";
pgClient.select(tenantQuery, promise);
return promise.future()
.map(rowSet -> StreamSupport.stream(rowSet.spliterator(), false)
.map(this::mapToTenant)
.collect(Collectors.toList())
);
String tenantQuery = """
select schemaname from pg_catalog.pg_tables
where schemaname LIKE $1 and tablename = $2
""";
return pgClient.execute(tenantQuery, Tuple.of("%" + SUFFIX, table))
.map(rowSet -> StreamSupport.stream(rowSet.spliterator(), false)
.map(this::mapToTenant)
.collect(Collectors.toList()));
}

private String mapToTenant(Row row) {
String nsTenant = row.getString("nspname");
String suffix = "_mod_source_record_storage";
int tenantNameLength = nsTenant.length() - suffix.length();
return nsTenant.substring(0, tenantNameLength);
String schemaname = row.getString("schemaname");
int tenantNameLength = schemaname.length() - SUFFIX.length();
return schemaname.substring(0, tenantNameLength);
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -57,7 +57,7 @@ public void start(Promise<Void> startFuture) {
Future<Boolean> deleteOldMarcIndexerVersions() {
LOGGER.info("Performing marc_indexers old versions deletion...");
long startTime = System.nanoTime();
return tenantDataProvider.getModuleTenants()
return tenantDataProvider.getModuleTenants("marc_records_tracking")
.onFailure(ar ->
LOGGER.error("could not get the list of tenants to delete marc indexer versions", ar.getCause()))
.compose(ar -> {
Expand Down

0 comments on commit 8b034e1

Please sign in to comment.