Skip to content

Commit

Permalink
#2665: [YSQL] one of Masters crashed when we tried to delete YSQL dat…
Browse files Browse the repository at this point in the history
…abase

Summary: Removed invalid check in the yb::master::CatalogManager::DeleteYsqlDatabase method.

Test Plan: ybd --java-test org.yb.multiapi.TestMultiAPI

Reviewers: alex, neha

Reviewed By: neha

Subscribers: dmitry, yql, bogdan

Differential Revision: https://phabricator.dev.yugabyte.com/D7464
  • Loading branch information
OlegLoginov authored and Cloud User committed Nov 1, 2019
1 parent cd648fe commit 6158182
Show file tree
Hide file tree
Showing 5 changed files with 230 additions and 3 deletions.
12 changes: 12 additions & 0 deletions java/pom.xml
Original file line number Diff line number Diff line change
Expand Up @@ -131,6 +131,7 @@
<module>yb-loadtester</module>
<module>yb-jedis-tests</module>
<module>yb-cdc</module>
<module>yb-multiapi</module>
</modules>

<build>
Expand Down Expand Up @@ -353,6 +354,11 @@
<artifactId>yb-cql</artifactId>
<version>${project.version}</version>
</dependency>
<dependency>
<groupId>org.yb</groupId>
<artifactId>yb-pgsql</artifactId>
<version>${project.version}</version>
</dependency>
<dependency>
<groupId>log4j</groupId>
<artifactId>log4j</artifactId>
Expand Down Expand Up @@ -492,6 +498,12 @@
<version>${project.version}</version>
<type>test-jar</type>
</dependency>
<dependency>
<groupId>org.yb</groupId>
<artifactId>yb-pgsql</artifactId>
<version>${project.version}</version>
<type>test-jar</type>
</dependency>

<dependency>
<groupId>org.postgresql</groupId>
Expand Down
114 changes: 114 additions & 0 deletions java/yb-multiapi/pom.xml
Original file line number Diff line number Diff line change
@@ -0,0 +1,114 @@
<?xml version="1.0"?>
<!-- Copyright (c) YugaByte, Inc. -->
<project
xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/xsd/maven-4.0.0.xsd"
xmlns="http://maven.apache.org/POM/4.0.0"
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance">
<modelVersion>4.0.0</modelVersion>
<parent>
<groupId>org.yb</groupId>
<artifactId>yb-parent</artifactId>
<version>0.8.0-SNAPSHOT</version>
</parent>

<artifactId>yb-multiapi</artifactId>
<name>YB Multi API</name>

<dependencies>
<dependency>
<groupId>org.yb</groupId>
<artifactId>yb-client</artifactId>
<type>test-jar</type>
<scope>test</scope>
</dependency>
<dependency>
<groupId>org.yb</groupId>
<artifactId>yb-client</artifactId>
<scope>test</scope>
</dependency>
<dependency>
<groupId>org.yb</groupId>
<artifactId>yb-cql</artifactId>
<type>test-jar</type>
<scope>test</scope>
<!-- Exclude Cassandra driver because it is already included by Spark -->
<exclusions>
<exclusion>
<groupId>com.yugabyte</groupId>
<artifactId>cassandra-driver-core</artifactId>
</exclusion>
</exclusions>
</dependency>
<dependency>
<groupId>org.yb</groupId>
<artifactId>yb-pgsql</artifactId>
<type>test-jar</type>
<scope>test</scope>
</dependency>
<dependency>
<groupId>${junit.groupId}</groupId>
<artifactId>junit</artifactId>
<scope>test</scope>
</dependency>
<dependency>
<groupId>commons-cli</groupId>
<artifactId>commons-cli</artifactId>
</dependency>
<dependency>
<groupId>commons-codec</groupId>
<artifactId>commons-codec</artifactId>
</dependency>
<dependency>
<groupId>org.apache.spark</groupId>
<artifactId>spark-core_2.10</artifactId>
</dependency>
<dependency>
<groupId>org.apache.spark</groupId>
<artifactId>spark-sql_2.10</artifactId>
</dependency>
<dependency>
<groupId>org.apache.commons</groupId>
<artifactId>commons-math3</artifactId>
<version>3.5</version>
</dependency>
<dependency>
<groupId>com.google.code.gson</groupId>
<artifactId>gson</artifactId>
</dependency>
<dependency>
<groupId>org.postgresql</groupId>
<artifactId>postgresql</artifactId>
<version>42.2.2</version>
</dependency>
</dependencies>

<build>
<plugins>
<plugin>
<groupId>org.apache.maven.plugins</groupId>
<artifactId>maven-dependency-plugin</artifactId>
<executions>
<execution>
<id>copy-dependencies</id>
<phase>${maven-dependency-plugin.phase}</phase>
<goals>
<goal>copy-dependencies</goal>
</goals>
<configuration>
<outputDirectory>${project.build.directory}/lib</outputDirectory>
<overWriteReleases>true</overWriteReleases>
<overWriteSnapshots>true</overWriteSnapshots>
<overWriteIfNewer>true</overWriteIfNewer>
</configuration>
</execution>
</executions>
</plugin>
<!-- make the jar executable by adding a Main-Class and Class-Path to the manifest -->
<plugin>
<groupId>org.apache.maven.plugins</groupId>
<artifactId>maven-jar-plugin</artifactId>
</plugin>
</plugins>
</build>

</project>
45 changes: 45 additions & 0 deletions java/yb-multiapi/src/test/java/org/yb/multiapi/TestMultiAPI.java
Original file line number Diff line number Diff line change
@@ -0,0 +1,45 @@
// Copyright (c) YugaByte, Inc.
//
// Licensed under the Apache License, Version 2.0 (the "License"); you may not use this file except
// in compliance with the License. You may obtain a copy of the License at
//
// http://www.apache.org/licenses/LICENSE-2.0
//
// Unless required by applicable law or agreed to in writing, software distributed under the License
// is distributed on an "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express
// or implied. See the License for the specific language governing permissions and limitations
// under the License.
//
package org.yb.multiapi;

import java.sql.Statement;
import org.junit.Test;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;

public class TestMultiAPI extends TestMultiAPIBase {
private static final Logger LOG = LoggerFactory.getLogger(TestMultiAPI.class);

// This tests the fix for issue https://github.com/YugaByte/yugabyte-db/issues/2665.
// Testing the case when there is CQL keyspace with the same name as a SQL DB.
@Test
public void testDropDB() throws Exception {
String dbName = "dtest";
LOG.info("Start test: " + getCurrentTestMethodName());

try (Statement statement = connection.createStatement()) {
LOG.info("Create SQL DB");
statement.execute(String.format("CREATE DATABASE %s", dbName));

LOG.info("Create CQL keyspace with used DB name");
cqlSession.execute(String.format("CREATE KEYSPACE %s", dbName));

LOG.info("Drop SQL DB");
statement.execute(String.format("DROP DATABASE %s", dbName));

LOG.info("Drop CQL keyspace");
cqlSession.execute(String.format("DROP KEYSPACE %s", dbName));
}
LOG.info("End test: " + getCurrentTestMethodName());
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,59 @@
// Copyright (c) YugaByte, Inc.
//
// Licensed under the Apache License, Version 2.0 (the "License"); you may not use this file except
// in compliance with the License. You may obtain a copy of the License at
//
// http://www.apache.org/licenses/LICENSE-2.0
//
// Unless required by applicable law or agreed to in writing, software distributed under the License
// is distributed on an "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express
// or implied. See the License for the specific language governing permissions and limitations
// under the License.
//
package org.yb.multiapi;

import java.util.Map;
import com.datastax.driver.core.Session;
import org.junit.BeforeClass;
import org.junit.Before;
import org.junit.After;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;

import org.yb.pgsql.BasePgSQLTest;
import org.yb.cql.BaseCQLTest;

public class TestMultiAPIBase extends BasePgSQLTest {
private static final Logger LOG = LoggerFactory.getLogger(TestMultiAPIBase.class);

public class CQLApi extends BaseCQLTest {
Session getSession() { return super.session; }
};

protected CQLApi cqlApi;
protected Session cqlSession;

@Override
protected Map<String, String> getTServerFlags() {
Map<String, String> flagMap = super.getTServerFlags();
flagMap.put("start_cql_proxy", Boolean.toString(true));
return flagMap;
}

@BeforeClass
public static void setUpBeforeClass() throws Exception {
BaseCQLTest.setUpBeforeClass();
}

@Before
public void setUpCql() throws Exception {
cqlApi = new CQLApi();
cqlApi.setUpCqlClient();
cqlSession = cqlApi.getSession();
}

@After
public void tearDownCql() throws Exception {
cqlApi.tearDownAfter();
}
}
3 changes: 0 additions & 3 deletions src/yb/master/catalog_manager.cc
Original file line number Diff line number Diff line change
Expand Up @@ -4137,9 +4137,6 @@ Status CatalogManager::DeleteYsqlDatabase(const DeleteNamespaceRequestPB* req,
{
TRACE("Removing from maps");
std::lock_guard<LockType> l_map(lock_);
CHECK(FindPtrOrNull(namespace_names_map_, database->name()) == nullptr)
<< "YSQL database name should not be included in namespace_names_map_. "
<< "If included, its name must be removed from map here when dropping";
if (namespace_ids_map_.erase(database->id()) < 1) {
PANIC_RPC(rpc, "Could not remove namespace from map, name=" + l->data().name());
}
Expand Down

0 comments on commit 6158182

Please sign in to comment.