Skip to content

Commit

Permalink
Add initialize() and clearAllData() APIs for MetaStore
Browse files Browse the repository at this point in the history
  • Loading branch information
velvia committed Sep 15, 2015
1 parent a30c44a commit 63a3b9d
Show file tree
Hide file tree
Showing 6 changed files with 30 additions and 17 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -8,10 +8,19 @@ import filodb.core.metadata.{Column, Dataset, MetaStore}

class CassandraMetaStore(config: Config)
(implicit val ec: ExecutionContext) extends MetaStore {

val datasetTable = DatasetTable
val columnTable = ColumnTable

def initialize(): Future[Response] =
for { dtResp <- datasetTable.initialize()
ctResp <- columnTable.initialize() }
yield { ctResp }

def clearAllData(): Future[Response] =
for { dtResp <- datasetTable.clearAll()
ctResp <- columnTable.clearAll() }
yield { ctResp }

def newDataset(dataset: Dataset): Future[Response] =
datasetTable.createNewDataset(dataset)

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -45,6 +45,10 @@ object ColumnTable extends ColumnTable with SimpleCassandraConnector {
import filodb.cassandra.Util._
import filodb.core._

def initialize(): Future[Response] = create.ifNotExists.future().toResponse()

def clearAll(): Future[Response] = truncate.future().toResponse()

def getSchema(dataset: String, version: Int): Future[Column.Schema] = {
val enum = select.where(_.dataset eqs dataset).and(_.version lte version)
.fetchEnumerator()
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -42,6 +42,10 @@ object DatasetTable extends DatasetTable with SimpleCassandraConnector {
import filodb.core._
import filodb.core.Types._

def initialize(): Future[Response] = create.ifNotExists.future().toResponse()

def clearAll(): Future[Response] = truncate.future().toResponse()

def insertProjection(projection: Projection): Future[Response] =
insert.value(_.name, projection.dataset)
.value(_.projectionId, projection.id)
Expand Down
14 changes: 0 additions & 14 deletions cassandra/src/test/scala/filodb.cassandra/AllTablesTest.scala
Original file line number Diff line number Diff line change
Expand Up @@ -37,20 +37,6 @@ trait AllTablesTest extends SimpleCassandraTest {

lazy val metaStore = new CassandraMetaStore(config)

def createAllTables(): Unit = {
val f = for { _ <- DatasetTable.create.ifNotExists.future()
_ <- ColumnTable.create.ifNotExists.future() }
yield { 0 }
Await.result(f, 10 seconds)
}

def truncateAllTables(): Unit = {
val f = for { _ <- DatasetTable.truncate.future()
_ <- ColumnTable.truncate.future() }
yield { 0 }
Await.result(f, 10 seconds)
}

import Column.ColumnType._

val dsName = "gdelt"
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -17,10 +17,10 @@ class CassandraMetaStoreSpec extends FunSpec with BeforeAndAfter with AllTablesT

override def beforeAll() {
super.beforeAll()
createAllTables()
metastore.initialize().futureValue
}

before { truncateAllTables() }
before { metastore.clearAllData().futureValue }

describe("column API") {
it("should return IllegalColumnChange if an invalid column addition submitted") {
Expand Down
10 changes: 10 additions & 0 deletions core/src/main/scala/filodb.core/metadata/MetaStore.scala
Original file line number Diff line number Diff line change
Expand Up @@ -17,6 +17,16 @@ trait MetaStore {

implicit val ec: ExecutionContext

/**
* Initializes the MetaStore so it is ready for further commands.
*/
def initialize(): Future[Response]

/**
* Clears all dataset and column metadata from the MetaStore.
*/
def clearAllData(): Future[Response]

/**
* ** Dataset API ***
*/
Expand Down

0 comments on commit 63a3b9d

Please sign in to comment.